This commit is contained in:
Amber Brown 2019-03-11 21:11:36 +11:00
parent 39e57f9728
commit 4abc988c6a
No known key found for this signature in database
GPG key ID: 20835A1515AB6FAC
5 changed files with 114 additions and 4 deletions

View file

@ -64,6 +64,10 @@ class UserDirectoryHandler(object):
# This is a set of user_id's we've inserted already
self.initially_handled_users = set()
self.register_background_update_handler(
"users_in_public_rooms_initial", self._populate_users_in_public_rooms
)
# The current position in the current_state_delta stream
self.pos = None
@ -77,6 +81,41 @@ class UserDirectoryHandler(object):
# we start populating the user directory
self.clock.call_later(0, self.notify_new_event)
@defer.inlineCallbacks
def _populate_users_in_public_rooms(self, progress, batch_size):
"""
Populate the users_in_public_rooms table with the contents of the
users_who_share_public_rooms table.
"""
def _fetch(txn):
sql = "SELECT DISTINCT other_user_id FROM users_who_share_public_rooms"
txn.execute(sql)
return txn.fetchall()
users = yield self.store.runInteraction(
"populate_users_in_public_rooms_fetch", _fetch
)
if users:
def _fill(txn):
self._simple_upsert_many_txn(
txn,
table="users_in_public_rooms",
key_names=["user_id"],
key_values=users,
value_names=(),
value_values=None,
)
users = yield self.store.runInteraction(
"populate_users_in_public_rooms_fill", _fill
)
yield self._end_background_update("users_in_public_rooms_initial")
defer.returnValue(1)
def search_users(self, user_id, search_term, limit):
"""Searches for users in directory
@ -231,7 +270,7 @@ class UserDirectoryHandler(object):
unhandled_users = user_ids - self.initially_handled_users
yield self.store.add_profiles_to_user_dir(
{user_id: users_with_profile[user_id] for user_id in unhandled_users},
{user_id: users_with_profile[user_id] for user_id in unhandled_users}
)
self.initially_handled_users |= unhandled_users