Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Make the get_global_account_data_by_type_for_user cache be a tree-c…
Browse files Browse the repository at this point in the history
…ache whose key is prefixed with the user ID (#11788)
  • Loading branch information
reivilibre committed Jan 21, 2022
1 parent e83520c commit 4c20965
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelog.d/11788.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove account data (including client config, push rules and ignored users) upon user deactivation.
2 changes: 1 addition & 1 deletion synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -1619,7 +1619,7 @@ async def _get_ignored_users(self, user_id: str) -> FrozenSet[str]:
# TODO: Can we `SELECT ignored_user_id FROM ignored_users WHERE ignorer_user_id=?;` instead?
ignored_account_data = (
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
)
)

Expand Down
2 changes: 1 addition & 1 deletion synapse/rest/client/account_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async def on_GET(
raise AuthError(403, "Cannot get account data for other users.")

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:
Expand Down
8 changes: 4 additions & 4 deletions synapse/storage/databases/main/account_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ def 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(
self, data_type: str, user_id: str
self, user_id: str, data_type: str
) -> Optional[JsonDict]:
"""
Returns:
Expand Down Expand Up @@ -392,7 +392,7 @@ def process_replication_rows(
for row in rows:
if not row.room_id:
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_room.invalidate((row.user_id, row.room_id))
Expand Down Expand Up @@ -476,7 +476,7 @@ async def add_account_data_for_user(
self._account_data_stream_cache.entity_has_changed(user_id, next_id)
self.get_account_data_for_user.invalidate((user_id,))
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()
Expand Down
2 changes: 1 addition & 1 deletion synapse/visibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async def filter_events_for_client(
)

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()
Expand Down
4 changes: 2 additions & 2 deletions tests/replication/slave/storage/test_account_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ def test_user_account_data(self):
)
self.replicate()
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.master_store.add_account_data_for_user(USER_ID, TYPE, {"a": 2})
)
self.replicate()
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}
)

0 comments on commit 4c20965

Please sign in to comment.