From 04d091fbcb466ffb1b3462a7fb8754952044aa24 Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Fri, 17 Feb 2023 11:11:29 +0000 Subject: Add another temporary table to the user directory background update for storing remote users needing lookup --- synapse/storage/databases/main/user_directory.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/synapse/storage/databases/main/user_directory.py b/synapse/storage/databases/main/user_directory.py index f2f618c8fd..45127deecd 100644 --- a/synapse/storage/databases/main/user_directory.py +++ b/synapse/storage/databases/main/user_directory.py @@ -142,6 +142,18 @@ class UserDirectoryBackgroundUpdateStore(StateDeltasStore): txn, TEMP_TABLE + "_users", keys=("user_id",), values=users ) + # A table for storing a list of remote users that *may* need a remote + # lookup in order to obtain a public profile. + # The list should be compared against the user directory's cache + # to see whether any queries can be skipped because the remote user + # also appeared in a public room. + sql = ( + "CREATE TABLE IF NOT EXISTS " + + TEMP_TABLE + + "_remote_users_needing_lookup(user_id TEXT PRIMARY KEY NOT NULL)" + ) + txn.execute(sql) + new_pos = await self.get_max_stream_id_in_current_state_deltas() await self.db_pool.runInteraction( "populate_user_directory_temp_build", _make_staging_area @@ -171,6 +183,9 @@ class UserDirectoryBackgroundUpdateStore(StateDeltasStore): def _delete_staging_area(txn: LoggingTransaction) -> None: txn.execute("DROP TABLE IF EXISTS " + TEMP_TABLE + "_rooms") txn.execute("DROP TABLE IF EXISTS " + TEMP_TABLE + "_users") + txn.execute( + "DROP TABLE IF EXISTS " + TEMP_TABLE + "_remote_users_needing_lookup" + ) txn.execute("DROP TABLE IF EXISTS " + TEMP_TABLE + "_position") await self.db_pool.runInteraction( -- cgit 1.4.1