mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
When a client asks for remote keys check if should resync. (#6797)
If we detect that the remote users' keys may have changed then we should attempt to resync against the remote server rather than using the (potentially) stale local cache.
This commit is contained in:
parent
5a246611e3
commit
c80a9fe13d
1
changelog.d/6797.misc
Normal file
1
changelog.d/6797.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
When a client asks for a remote user's device keys check if the local cache for that user has been marked as potentially stale.
|
@ -32,7 +32,7 @@ from synapse.logging.opentracing import (
|
|||||||
from synapse.metrics.background_process_metrics import run_as_background_process
|
from synapse.metrics.background_process_metrics import run_as_background_process
|
||||||
from synapse.storage._base import SQLBaseStore, db_to_json, make_in_list_sql_clause
|
from synapse.storage._base import SQLBaseStore, db_to_json, make_in_list_sql_clause
|
||||||
from synapse.storage.database import Database
|
from synapse.storage.database import Database
|
||||||
from synapse.types import get_verify_key_from_cross_signing_key
|
from synapse.types import Collection, get_verify_key_from_cross_signing_key
|
||||||
from synapse.util.caches.descriptors import (
|
from synapse.util.caches.descriptors import (
|
||||||
Cache,
|
Cache,
|
||||||
cached,
|
cached,
|
||||||
@ -443,8 +443,15 @@ class DeviceWorkerStore(SQLBaseStore):
|
|||||||
"""
|
"""
|
||||||
user_ids = set(user_id for user_id, _ in query_list)
|
user_ids = set(user_id for user_id, _ in query_list)
|
||||||
user_map = yield self.get_device_list_last_stream_id_for_remotes(list(user_ids))
|
user_map = yield self.get_device_list_last_stream_id_for_remotes(list(user_ids))
|
||||||
user_ids_in_cache = set(
|
|
||||||
user_id for user_id, stream_id in user_map.items() if stream_id
|
# We go and check if any of the users need to have their device lists
|
||||||
|
# resynced. If they do then we remove them from the cached list.
|
||||||
|
users_needing_resync = yield self.get_user_ids_requiring_device_list_resync(
|
||||||
|
user_ids
|
||||||
|
)
|
||||||
|
user_ids_in_cache = (
|
||||||
|
set(user_id for user_id, stream_id in user_map.items() if stream_id)
|
||||||
|
- users_needing_resync
|
||||||
)
|
)
|
||||||
user_ids_not_in_cache = user_ids - user_ids_in_cache
|
user_ids_not_in_cache = user_ids - user_ids_in_cache
|
||||||
|
|
||||||
@ -641,6 +648,25 @@ class DeviceWorkerStore(SQLBaseStore):
|
|||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def get_user_ids_requiring_device_list_resync(self, user_ids: Collection[str]):
|
||||||
|
"""Given a list of remote users return the list of users that we
|
||||||
|
should resync the device lists for.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Deferred[Set[str]]
|
||||||
|
"""
|
||||||
|
|
||||||
|
rows = yield self.db.simple_select_many_batch(
|
||||||
|
table="device_lists_remote_resync",
|
||||||
|
column="user_id",
|
||||||
|
iterable=user_ids,
|
||||||
|
retcols=("user_id",),
|
||||||
|
desc="get_user_ids_requiring_device_list_resync",
|
||||||
|
)
|
||||||
|
|
||||||
|
return {row["user_id"] for row in rows}
|
||||||
|
|
||||||
def mark_remote_user_device_cache_as_stale(self, user_id: str):
|
def mark_remote_user_device_cache_as_stale(self, user_id: str):
|
||||||
"""Records that the server has reason to believe the cache of the devices
|
"""Records that the server has reason to believe the cache of the devices
|
||||||
for the remote users is out of date.
|
for the remote users is out of date.
|
||||||
|
Loading…
Reference in New Issue
Block a user