forked from MirrorHub/synapse
Make the get_global_account_data_by_type_for_user
cache be a tree-cache whose key is prefixed with the user ID (#11788)
This commit is contained in:
parent
e83520cc42
commit
4c2096599c
1
changelog.d/11788.feature
Normal file
1
changelog.d/11788.feature
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Remove account data (including client config, push rules and ignored users) upon user deactivation.
|
|
@ -1619,7 +1619,7 @@ class SyncHandler:
|
||||||
# TODO: Can we `SELECT ignored_user_id FROM ignored_users WHERE ignorer_user_id=?;` instead?
|
# TODO: Can we `SELECT ignored_user_id FROM ignored_users WHERE ignorer_user_id=?;` instead?
|
||||||
ignored_account_data = (
|
ignored_account_data = (
|
||||||
await self.store.get_global_account_data_by_type_for_user(
|
await self.store.get_global_account_data_by_type_for_user(
|
||||||
AccountDataTypes.IGNORED_USER_LIST, user_id=user_id
|
user_id=user_id, data_type=AccountDataTypes.IGNORED_USER_LIST
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ class AccountDataServlet(RestServlet):
|
||||||
raise AuthError(403, "Cannot get account data for other users.")
|
raise AuthError(403, "Cannot get account data for other users.")
|
||||||
|
|
||||||
event = await self.store.get_global_account_data_by_type_for_user(
|
event = await self.store.get_global_account_data_by_type_for_user(
|
||||||
account_data_type, user_id
|
user_id, account_data_type
|
||||||
)
|
)
|
||||||
|
|
||||||
if event is None:
|
if event is None:
|
||||||
|
|
|
@ -158,9 +158,9 @@ class AccountDataWorkerStore(CacheInvalidationWorkerStore):
|
||||||
"get_account_data_for_user", get_account_data_for_user_txn
|
"get_account_data_for_user", get_account_data_for_user_txn
|
||||||
)
|
)
|
||||||
|
|
||||||
@cached(num_args=2, max_entries=5000)
|
@cached(num_args=2, max_entries=5000, tree=True)
|
||||||
async def get_global_account_data_by_type_for_user(
|
async def get_global_account_data_by_type_for_user(
|
||||||
self, data_type: str, user_id: str
|
self, user_id: str, data_type: str
|
||||||
) -> Optional[JsonDict]:
|
) -> Optional[JsonDict]:
|
||||||
"""
|
"""
|
||||||
Returns:
|
Returns:
|
||||||
|
@ -392,7 +392,7 @@ class AccountDataWorkerStore(CacheInvalidationWorkerStore):
|
||||||
for row in rows:
|
for row in rows:
|
||||||
if not row.room_id:
|
if not row.room_id:
|
||||||
self.get_global_account_data_by_type_for_user.invalidate(
|
self.get_global_account_data_by_type_for_user.invalidate(
|
||||||
(row.data_type, row.user_id)
|
(row.user_id, row.data_type)
|
||||||
)
|
)
|
||||||
self.get_account_data_for_user.invalidate((row.user_id,))
|
self.get_account_data_for_user.invalidate((row.user_id,))
|
||||||
self.get_account_data_for_room.invalidate((row.user_id, row.room_id))
|
self.get_account_data_for_room.invalidate((row.user_id, row.room_id))
|
||||||
|
@ -476,7 +476,7 @@ class AccountDataWorkerStore(CacheInvalidationWorkerStore):
|
||||||
self._account_data_stream_cache.entity_has_changed(user_id, next_id)
|
self._account_data_stream_cache.entity_has_changed(user_id, next_id)
|
||||||
self.get_account_data_for_user.invalidate((user_id,))
|
self.get_account_data_for_user.invalidate((user_id,))
|
||||||
self.get_global_account_data_by_type_for_user.invalidate(
|
self.get_global_account_data_by_type_for_user.invalidate(
|
||||||
(account_data_type, user_id)
|
(user_id, account_data_type)
|
||||||
)
|
)
|
||||||
|
|
||||||
return self._account_data_id_gen.get_current_token()
|
return self._account_data_id_gen.get_current_token()
|
||||||
|
|
|
@ -87,7 +87,7 @@ async def filter_events_for_client(
|
||||||
)
|
)
|
||||||
|
|
||||||
ignore_dict_content = await storage.main.get_global_account_data_by_type_for_user(
|
ignore_dict_content = await storage.main.get_global_account_data_by_type_for_user(
|
||||||
AccountDataTypes.IGNORED_USER_LIST, user_id
|
user_id, AccountDataTypes.IGNORED_USER_LIST
|
||||||
)
|
)
|
||||||
|
|
||||||
ignore_list: FrozenSet[str] = frozenset()
|
ignore_list: FrozenSet[str] = frozenset()
|
||||||
|
|
|
@ -30,7 +30,7 @@ class SlavedAccountDataStoreTestCase(BaseSlavedStoreTestCase):
|
||||||
)
|
)
|
||||||
self.replicate()
|
self.replicate()
|
||||||
self.check(
|
self.check(
|
||||||
"get_global_account_data_by_type_for_user", [TYPE, USER_ID], {"a": 1}
|
"get_global_account_data_by_type_for_user", [USER_ID, TYPE], {"a": 1}
|
||||||
)
|
)
|
||||||
|
|
||||||
self.get_success(
|
self.get_success(
|
||||||
|
@ -38,5 +38,5 @@ class SlavedAccountDataStoreTestCase(BaseSlavedStoreTestCase):
|
||||||
)
|
)
|
||||||
self.replicate()
|
self.replicate()
|
||||||
self.check(
|
self.check(
|
||||||
"get_global_account_data_by_type_for_user", [TYPE, USER_ID], {"a": 2}
|
"get_global_account_data_by_type_for_user", [USER_ID, TYPE], {"a": 2}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue