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

Commit

Permalink
Speed up fetching large numbers of push rules (#13592)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston authored Aug 23, 2022
1 parent 5e7847d commit aec87a0
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelog.d/13592.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Minor speed up of fetching large numbers of push rules.
1 change: 0 additions & 1 deletion synapse/replication/slave/storage/push_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ def process_replication_rows(
self._push_rules_stream_id_gen.advance(instance_name, token)
for row in rows:
self.get_push_rules_for_user.invalidate((row.user_id,))
self.get_push_rules_enabled_for_user.invalidate((row.user_id,))
self.push_rules_stream_cache.entity_has_changed(row.user_id, token)
return super().process_replication_rows(stream_name, instance_name, token, rows)
3 changes: 0 additions & 3 deletions synapse/storage/databases/main/account_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,9 +650,6 @@ def _purge_account_data_for_user_txn(
txn, self.get_account_data_for_room, (user_id,)
)
self._invalidate_cache_and_stream(txn, self.get_push_rules_for_user, (user_id,))
self._invalidate_cache_and_stream(
txn, self.get_push_rules_enabled_for_user, (user_id,)
)
# This user might be contained in the ignored_by cache for other users,
# so we have to invalidate it all.
self._invalidate_all_cache_and_stream(txn, self.ignored_by)
Expand Down
6 changes: 1 addition & 5 deletions synapse/storage/databases/main/push_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ async def get_push_rules_for_user(self, user_id: str) -> FilteredPushRules:

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

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

return results

@cachedList(
cached_method_name="get_push_rules_enabled_for_user", list_name="user_ids"
)
async def bulk_get_push_rules_enabled(
self, user_ids: Collection[str]
) -> Dict[str, Dict[str, bool]]:
Expand All @@ -246,6 +242,7 @@ async def bulk_get_push_rules_enabled(
iterable=user_ids,
retcols=("user_name", "rule_id", "enabled"),
desc="bulk_get_push_rules_enabled",
batch_size=1000,
)
for row in rows:
enabled = bool(row["enabled"])
Expand Down Expand Up @@ -792,7 +789,6 @@ def _insert_push_rules_update_txn(
self.db_pool.simple_insert_txn(txn, "push_rules_stream", values=values)

txn.call_after(self.get_push_rules_for_user.invalidate, (user_id,))
txn.call_after(self.get_push_rules_enabled_for_user.invalidate, (user_id,))
txn.call_after(
self.push_rules_stream_cache.entity_has_changed, user_id, stream_id
)
Expand Down

0 comments on commit aec87a0

Please sign in to comment.