mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-09-07 23:32:00 +00:00
Batching in the user directory import (#4900)
This commit is contained in:
parent
cdb8036161
commit
4d53017432
1
changelog.d/4900.feature
Normal file
1
changelog.d/4900.feature
Normal file
@ -0,0 +1 @@
|
||||
The user directory has been rewritten to make it faster, with less chance of falling behind on a large server.
|
@ -32,6 +32,11 @@ TEMP_TABLE = "_temp_populate_user_directory"
|
||||
|
||||
|
||||
class UserDirectoryStore(BackgroundUpdateStore):
|
||||
|
||||
# How many records do we calculate before sending it to
|
||||
# add_users_who_share_private_rooms?
|
||||
SHARE_PRIVATE_WORKING_SET = 500
|
||||
|
||||
def __init__(self, db_conn, hs):
|
||||
super(UserDirectoryStore, self).__init__(db_conn, hs)
|
||||
|
||||
@ -218,6 +223,14 @@ class UserDirectoryStore(BackgroundUpdateStore):
|
||||
user_set = (user_id, other_user_id)
|
||||
to_insert.add(user_set)
|
||||
|
||||
# If it gets too big, stop and write to the database
|
||||
# to prevent storing too much in RAM.
|
||||
if len(to_insert) >= self.SHARE_PRIVATE_WORKING_SET:
|
||||
yield self.add_users_who_share_private_room(
|
||||
room_id, to_insert
|
||||
)
|
||||
to_insert.clear()
|
||||
|
||||
if to_insert:
|
||||
yield self.add_users_who_share_private_room(room_id, to_insert)
|
||||
to_insert.clear()
|
||||
|
Loading…
Reference in New Issue
Block a user