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

Commit aec87a0

Browse files
authored
Speed up fetching large numbers of push rules (#13592)
1 parent 5e7847d commit aec87a0

File tree

4 files changed

+2
-9
lines changed

4 files changed

+2
-9
lines changed

changelog.d/13592.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Minor speed up of fetching large numbers of push rules.

synapse/replication/slave/storage/push_rule.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,5 @@ def process_replication_rows(
3131
self._push_rules_stream_id_gen.advance(instance_name, token)
3232
for row in rows:
3333
self.get_push_rules_for_user.invalidate((row.user_id,))
34-
self.get_push_rules_enabled_for_user.invalidate((row.user_id,))
3534
self.push_rules_stream_cache.entity_has_changed(row.user_id, token)
3635
return super().process_replication_rows(stream_name, instance_name, token, rows)

synapse/storage/databases/main/account_data.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,6 @@ def _purge_account_data_for_user_txn(
650650
txn, self.get_account_data_for_room, (user_id,)
651651
)
652652
self._invalidate_cache_and_stream(txn, self.get_push_rules_for_user, (user_id,))
653-
self._invalidate_cache_and_stream(
654-
txn, self.get_push_rules_enabled_for_user, (user_id,)
655-
)
656653
# This user might be contained in the ignored_by cache for other users,
657654
# so we have to invalidate it all.
658655
self._invalidate_all_cache_and_stream(txn, self.ignored_by)

synapse/storage/databases/main/push_rule.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ async def get_push_rules_for_user(self, user_id: str) -> FilteredPushRules:
165165

166166
return _load_rules(rows, enabled_map, self.hs.config.experimental)
167167

168-
@cached(max_entries=5000)
169168
async def get_push_rules_enabled_for_user(self, user_id: str) -> Dict[str, bool]:
170169
results = await self.db_pool.simple_select_list(
171170
table="push_rules_enable",
@@ -229,9 +228,6 @@ async def bulk_get_push_rules(
229228

230229
return results
231230

232-
@cachedList(
233-
cached_method_name="get_push_rules_enabled_for_user", list_name="user_ids"
234-
)
235231
async def bulk_get_push_rules_enabled(
236232
self, user_ids: Collection[str]
237233
) -> Dict[str, Dict[str, bool]]:
@@ -246,6 +242,7 @@ async def bulk_get_push_rules_enabled(
246242
iterable=user_ids,
247243
retcols=("user_name", "rule_id", "enabled"),
248244
desc="bulk_get_push_rules_enabled",
245+
batch_size=1000,
249246
)
250247
for row in rows:
251248
enabled = bool(row["enabled"])
@@ -792,7 +789,6 @@ def _insert_push_rules_update_txn(
792789
self.db_pool.simple_insert_txn(txn, "push_rules_stream", values=values)
793790

794791
txn.call_after(self.get_push_rules_for_user.invalidate, (user_id,))
795-
txn.call_after(self.get_push_rules_enabled_for_user.invalidate, (user_id,))
796792
txn.call_after(
797793
self.push_rules_stream_cache.entity_has_changed, user_id, stream_id
798794
)

0 commit comments

Comments
 (0)