Docstring. And small optimisations.

This commit is contained in:
Jorik Schellekens 2019-07-18 16:32:06 +01:00
parent 4776528a3f
commit ff85bbb2d9

View file

@ -133,6 +133,12 @@ class E2eKeysHandler(object):
@opentracing.trace_deferred @opentracing.trace_deferred
@defer.inlineCallbacks @defer.inlineCallbacks
def do_remote_query(destination): def do_remote_query(destination):
"""This is called when we are querying the device list of a user on
a remote homeserver and their device list is not in the device list
cache. If we share a room with this user and we're not querying for
specific user we will update the cache
with their device list."""
destination_query = remote_queries_not_in_cache[destination] destination_query = remote_queries_not_in_cache[destination]
opentracing.set_tag("key_query", destination_query) opentracing.set_tag("key_query", destination_query)
@ -149,39 +155,43 @@ class E2eKeysHandler(object):
if user_id not in user_ids_updated: if user_id not in user_ids_updated:
try: try:
with PreserveLoggingContext(LoggingContext.current_context()): with PreserveLoggingContext(LoggingContext.current_context()):
room_ids = yield self.store.get_rooms_for_user(user_id) if not device_list:
if not device_list and room_ids: room_ids = yield self.store.get_rooms_for_user(user_id)
opentracing.log_kv( if room_ids:
{ # We've decided we're sharing a room with this user and should
"message": "Resyncing devices for user", # probably be tracking their device lists. However, we haven't
"user_id": user_id, # done an initial sync on the device list so we do it now.
} opentracing.log_kv(
) {
user_devices = yield self.device_handler.device_list_updater.user_device_resync( "message": "Resyncing devices for user",
user_id "user_id": user_id,
) }
user_devices = user_devices["devices"] )
opentracing.log_kv( user_devices = yield self.device_handler.device_list_updater.user_device_resync(
{ user_id
"message": "got user devices", )
"user_devices": user_devices, user_devices = user_devices["devices"]
} opentracing.log_kv(
) {
for device in user_devices: "message": "got user devices",
results[user_id] = { "user_devices": user_devices,
device["device_id"]: device["keys"] }
} )
opentracing.log_kv( for device in user_devices:
{"adding user to user_ids_updated": user_id} results[user_id] = {
) device["device_id"]: device["keys"]
user_ids_updated.append(user_id) }
else: opentracing.log_kv(
opentracing.log_kv( {"adding user to user_ids_updated": user_id}
{ )
"message": "Not resyncing devices for user", user_ids_updated.append(user_id)
"user_id": user_id, else:
} opentracing.log_kv(
) {
"message": "Not resyncing devices for user",
"user_id": user_id,
}
)
except Exception as e: except Exception as e:
failures[destination] = failures.get(destination, []).append( failures[destination] = failures.get(destination, []).append(
_exception_to_failure(e) _exception_to_failure(e)