From 43f1c82457e4ce2ef9805829d86dc8791b56bbd5 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Thu, 18 Feb 2021 08:44:19 -0500 Subject: Add back the guard against the user directory stream position not existing. (#9428) As the comment says, this guard was there for when the initial user directory update has yet to happen. --- synapse/handlers/user_directory.py | 4 ++++ synapse/storage/databases/main/user_directory.py | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'synapse') diff --git a/synapse/handlers/user_directory.py b/synapse/handlers/user_directory.py index 3dfb0a26c2..1a8340000a 100644 --- a/synapse/handlers/user_directory.py +++ b/synapse/handlers/user_directory.py @@ -143,6 +143,10 @@ class UserDirectoryHandler(StateDeltasHandler): if self.pos is None: self.pos = await self.store.get_user_directory_stream_pos() + # If still None then the initial background update hasn't happened yet. + if self.pos is None: + return None + # Loop round handling deltas until we're up to date while True: with Measure(self.clock, "user_dir_delta"): diff --git a/synapse/storage/databases/main/user_directory.py b/synapse/storage/databases/main/user_directory.py index 3a1fe3ed52..63f88eac51 100644 --- a/synapse/storage/databases/main/user_directory.py +++ b/synapse/storage/databases/main/user_directory.py @@ -707,7 +707,13 @@ class UserDirectoryStore(UserDirectoryBackgroundUpdateStore): return {row["room_id"] for row in rows} - async def get_user_directory_stream_pos(self) -> int: + async def get_user_directory_stream_pos(self) -> Optional[int]: + """ + Get the stream ID of the user directory stream. + + Returns: + The stream token or None if the initial background update hasn't happened yet. + """ return await self.db_pool.simple_select_one_onecol( table="user_directory_stream_pos", keyvalues={}, -- cgit 1.4.1