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

Commit

Permalink
Misc clean-up of push rules datastore (#12856)
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep authored May 25, 2022
1 parent 6aeee9a commit 4cbcd4a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
1 change: 1 addition & 0 deletions changelog.d/12856.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clean-up the push rules datastore.
16 changes: 5 additions & 11 deletions synapse/storage/databases/main/push_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ async def get_push_rules_for_user(self, user_id: str) -> List[JsonDict]:
"conditions",
"actions",
),
desc="get_push_rules_enabled_for_user",
desc="get_push_rules_for_user",
)

rows.sort(key=lambda row: (-int(row["priority_class"]), -int(row["priority"])))
Expand All @@ -188,10 +188,10 @@ 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",
keyvalues={"user_name": user_id},
retcols=("user_name", "rule_id", "enabled"),
retcols=("rule_id", "enabled"),
desc="get_push_rules_enabled_for_user",
)
return {r["rule_id"]: False if r["enabled"] == 0 else True for r in results}
return {r["rule_id"]: bool(r["enabled"]) for r in results}

async def have_push_rules_changed_for_user(
self, user_id: str, last_id: int
Expand All @@ -213,11 +213,7 @@ def have_push_rules_changed_txn(txn: LoggingTransaction) -> bool:
"have_push_rules_changed", have_push_rules_changed_txn
)

@cachedList(
cached_method_name="get_push_rules_for_user",
list_name="user_ids",
num_args=1,
)
@cachedList(cached_method_name="get_push_rules_for_user", list_name="user_ids")
async def bulk_get_push_rules(
self, user_ids: Collection[str]
) -> Dict[str, List[JsonDict]]:
Expand Down Expand Up @@ -249,9 +245,7 @@ async def bulk_get_push_rules(
return results

@cachedList(
cached_method_name="get_push_rules_enabled_for_user",
list_name="user_ids",
num_args=1,
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]
Expand Down

0 comments on commit 4cbcd4a

Please sign in to comment.