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

Misc clean-up of push rules datastore #12856

Merged
merged 4 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe this is meant to be the same description? It isn't really clear to me. Nothing else seems to call get_push_rules_enabled_for_user, which shares the description as this.

)

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