4040
4141logger = logging .getLogger (__name__ )
4242
43-
4443TEMP_TABLE = "_temp_populate_user_directory"
4544
4645
4746class UserDirectoryBackgroundUpdateStore (StateDeltasStore ):
48-
4947 # How many records do we calculate before sending it to
5048 # add_users_who_share_private_rooms?
5149 SHARE_PRIVATE_WORKING_SET = 500
@@ -235,13 +233,16 @@ def _get_next_batch(
235233 )
236234
237235 users_with_profile = await self .get_users_in_room_with_profiles (room_id )
236+ # Throw away users excluded from the directory.
237+ users_with_profile = {
238+ user_id : profile
239+ for user_id , profile in users_with_profile .items ()
240+ if not self .hs .is_mine_id (user_id )
241+ or await self .should_include_local_user_in_dir (user_id )
242+ }
238243
239244 # Update each user in the user directory.
240245 for user_id , profile in users_with_profile .items ():
241- if self .hs .is_mine_id (
242- user_id
243- ) and not await self .should_include_local_user_in_dir (user_id ):
244- continue
245246 await self .update_profile_in_user_dir (
246247 user_id , profile .display_name , profile .avatar_url
247248 )
@@ -250,24 +251,19 @@ def _get_next_batch(
250251
251252 if is_public :
252253 for user_id in users_with_profile :
253- if self .hs .is_mine_id (
254- user_id
255- ) and not await self .should_include_local_user_in_dir (user_id ):
256- continue
257-
258254 to_insert .add (user_id )
259255
260256 if to_insert :
261257 await self .add_users_in_public_rooms (room_id , to_insert )
262258 to_insert .clear ()
263259 else :
264260 for user_id in users_with_profile :
261+ # We want the set of pairs (L, M) where L and M are
262+ # in `users_with_profile` and L is local.
263+ # Do so by looking for the local user L first.
265264 if not self .hs .is_mine_id (user_id ):
266265 continue
267266
268- if not await self .should_include_local_user_in_dir (user_id ):
269- continue
270-
271267 for other_user_id in users_with_profile :
272268 if user_id == other_user_id :
273269 continue
@@ -562,7 +558,6 @@ async def update_user_directory_stream_pos(self, stream_id: Optional[int]) -> No
562558
563559
564560class UserDirectoryStore (UserDirectoryBackgroundUpdateStore ):
565-
566561 # How many records do we calculate before sending it to
567562 # add_users_who_share_private_rooms?
568563 SHARE_PRIVATE_WORKING_SET = 500
0 commit comments