forked-synapse/synapse/storage
David Robertson f7b034a24b
Consistently exclude from user_directory (#10960)
* Introduce `should_include_local_users_in_dir`

We exclude three kinds of local users from the user_directory tables. At
present we don't consistently exclude all three in the same places. This
commit introduces a new function to gather those exclusion conditions
together. Because we have to handle local and remote users in different
ways, I've made that function only consider the case of remote users.
It's the caller's responsibility to make the local versus remote
distinction clear and correct.

A test fixup is required. The test now hits a path which makes db
queries against the users table. The expected rows were missing, because
we were using a dummy user that hadn't actually been registered.

We also add new test cases to covert the exclusion logic.

----

By my reading this makes these changes:

* When an app service user registers or changes their profile, they will
  _not_ be added to the user directory. (Previously only support and
  deactivated users were excluded). This is consistent with the logic that
  rebuilds the user directory. See also [the discussion
  here](https://github.com/matrix-org/synapse/pull/10914#discussion_r716859548).
* When rebuilding the directory, exclude support and disabled users from
  room sharing tables. Previously only appservice users were excluded.
* Exclude all three categories of local users when rebuilding the
  directory. Previously `_populate_user_directory_process_users` didn't do
  any exclusion.

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
2021-10-04 11:45:51 +00:00
..
databases Consistently exclude from user_directory (#10960) 2021-10-04 11:45:51 +00:00
engines Fix the inbound PDU metric (#10279) 2021-06-30 12:07:16 +01:00
schema Drop backwards-compatibility support for "outlier" (#10903) 2021-09-28 15:25:36 +01:00
util Speed up MultiWriterIdGenerator when lots of IDs are in flight. (#10755) 2021-09-03 18:23:46 +01:00
__init__.py Remove redundant "coding: utf-8" lines (#9786) 2021-04-14 15:34:27 +01:00
_base.py Remove unnecessary SystemRandom from SQLBaseStore (#9987) 2021-05-14 10:59:10 +01:00
background_updates.py Use inline type hints in http/federation/, storage/ and util/ (#10381) 2021-07-15 12:46:54 -04:00
database.py Fix remove_stale_pushers job on SQLite. (#10843) 2021-09-20 10:26:13 +01:00
keys.py Remove redundant "coding: utf-8" lines (#9786) 2021-04-14 15:34:27 +01:00
persist_events.py Generics for ObservableDeferred (#10491) 2021-07-28 19:55:50 +00:00
prepare_database.py Use direct references for configuration variables (part 6). (#10916) 2021-09-29 06:44:15 -04:00
purge_events.py Remove redundant "coding: utf-8" lines (#9786) 2021-04-14 15:34:27 +01:00
push_rule.py Remove redundant "coding: utf-8" lines (#9786) 2021-04-14 15:34:27 +01:00
relations.py Name the type of token in "Invalid token" messages (#10815) 2021-09-14 11:25:05 +01:00
roommember.py Do not include rooms with an unknown room version in a sync response. (#10644) 2021-08-19 11:12:55 -04:00
state.py Add type hints to state database module. (#10823) 2021-09-15 09:54:13 -04:00
types.py Remove redundant "coding: utf-8" lines (#9786) 2021-04-14 15:34:27 +01:00