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

Commit 4c20965

Browse files
authored
Make the get_global_account_data_by_type_for_user cache be a tree-cache whose key is prefixed with the user ID (#11788)
1 parent e83520c commit 4c20965

File tree

6 files changed

+10
-9
lines changed

6 files changed

+10
-9
lines changed

changelog.d/11788.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove account data (including client config, push rules and ignored users) upon user deactivation.

synapse/handlers/sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,7 @@ async def _get_ignored_users(self, user_id: str) -> FrozenSet[str]:
16191619
# TODO: Can we `SELECT ignored_user_id FROM ignored_users WHERE ignorer_user_id=?;` instead?
16201620
ignored_account_data = (
16211621
await self.store.get_global_account_data_by_type_for_user(
1622-
AccountDataTypes.IGNORED_USER_LIST, user_id=user_id
1622+
user_id=user_id, data_type=AccountDataTypes.IGNORED_USER_LIST
16231623
)
16241624
)
16251625

synapse/rest/client/account_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async def on_GET(
6666
raise AuthError(403, "Cannot get account data for other users.")
6767

6868
event = await self.store.get_global_account_data_by_type_for_user(
69-
account_data_type, user_id
69+
user_id, account_data_type
7070
)
7171

7272
if event is None:

synapse/storage/databases/main/account_data.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ def get_account_data_for_user_txn(
158158
"get_account_data_for_user", get_account_data_for_user_txn
159159
)
160160

161-
@cached(num_args=2, max_entries=5000)
161+
@cached(num_args=2, max_entries=5000, tree=True)
162162
async def get_global_account_data_by_type_for_user(
163-
self, data_type: str, user_id: str
163+
self, user_id: str, data_type: str
164164
) -> Optional[JsonDict]:
165165
"""
166166
Returns:
@@ -392,7 +392,7 @@ def process_replication_rows(
392392
for row in rows:
393393
if not row.room_id:
394394
self.get_global_account_data_by_type_for_user.invalidate(
395-
(row.data_type, row.user_id)
395+
(row.user_id, row.data_type)
396396
)
397397
self.get_account_data_for_user.invalidate((row.user_id,))
398398
self.get_account_data_for_room.invalidate((row.user_id, row.room_id))
@@ -476,7 +476,7 @@ async def add_account_data_for_user(
476476
self._account_data_stream_cache.entity_has_changed(user_id, next_id)
477477
self.get_account_data_for_user.invalidate((user_id,))
478478
self.get_global_account_data_by_type_for_user.invalidate(
479-
(account_data_type, user_id)
479+
(user_id, account_data_type)
480480
)
481481

482482
return self._account_data_id_gen.get_current_token()

synapse/visibility.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ async def filter_events_for_client(
8787
)
8888

8989
ignore_dict_content = await storage.main.get_global_account_data_by_type_for_user(
90-
AccountDataTypes.IGNORED_USER_LIST, user_id
90+
user_id, AccountDataTypes.IGNORED_USER_LIST
9191
)
9292

9393
ignore_list: FrozenSet[str] = frozenset()

tests/replication/slave/storage/test_account_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ def test_user_account_data(self):
3030
)
3131
self.replicate()
3232
self.check(
33-
"get_global_account_data_by_type_for_user", [TYPE, USER_ID], {"a": 1}
33+
"get_global_account_data_by_type_for_user", [USER_ID, TYPE], {"a": 1}
3434
)
3535

3636
self.get_success(
3737
self.master_store.add_account_data_for_user(USER_ID, TYPE, {"a": 2})
3838
)
3939
self.replicate()
4040
self.check(
41-
"get_global_account_data_by_type_for_user", [TYPE, USER_ID], {"a": 2}
41+
"get_global_account_data_by_type_for_user", [USER_ID, TYPE], {"a": 2}
4242
)

0 commit comments

Comments
 (0)