From 7c549dd5572b2881ee61cb11c572a82662414cdb Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 14 May 2015 11:44:03 +0100 Subject: Add ID generator for push_rules_enable to #resolve SYN-378 --- synapse/storage/push_rule.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'synapse/storage/push_rule.py') diff --git a/synapse/storage/push_rule.py b/synapse/storage/push_rule.py index 34805e276e..e7988676ce 100644 --- a/synapse/storage/push_rule.py +++ b/synapse/storage/push_rule.py @@ -204,11 +204,21 @@ class PushRuleStore(SQLBaseStore): @defer.inlineCallbacks def set_push_rule_enabled(self, user_name, rule_id, enabled): - yield self._simple_upsert( + ret = yield self.runInteraction( + "_set_push_rule_enabled_txn", + self._set_push_rule_enabled_txn, + user_name, rule_id, enabled + ) + defer.returnValue(ret) + + def _set_push_rule_enabled_txn(self, txn, user_name, rule_id, enabled): + new_id = self._push_rules_enable_id_gen.get_next_txn(txn) + self._simple_upsert_txn( + txn, PushRuleEnableTable.table_name, {'user_name': user_name, 'rule_id': rule_id}, {'enabled': 1 if enabled else 0}, - desc="set_push_rule_enabled", + {'id': new_id}, ) -- cgit 1.4.1 From a04cde613e7b271b1c34409e614da12a1da52432 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Fri, 22 May 2015 10:39:45 +0100 Subject: Add a cache for get_push rules for user, fix cache invalidation --- synapse/storage/push_rule.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'synapse/storage/push_rule.py') diff --git a/synapse/storage/push_rule.py b/synapse/storage/push_rule.py index 80d0ac4ea3..4cac118d17 100644 --- a/synapse/storage/push_rule.py +++ b/synapse/storage/push_rule.py @@ -23,6 +23,7 @@ logger = logging.getLogger(__name__) class PushRuleStore(SQLBaseStore): + @cached() @defer.inlineCallbacks def get_push_rules_for_user(self, user_name): rows = yield self._simple_select_list( @@ -31,6 +32,7 @@ class PushRuleStore(SQLBaseStore): "user_name": user_name, }, retcols=PushRuleTable.fields, + desc="get_push_rules_enabled_for_user", ) rows.sort( @@ -150,6 +152,10 @@ class PushRuleStore(SQLBaseStore): txn.execute(sql, (user_name, priority_class, new_rule_priority)) + txn.call_after( + self.get_push_rules_for_user.invalidate, user_name + ) + txn.call_after( self.get_push_rules_enabled_for_user.invalidate, user_name ) @@ -182,6 +188,9 @@ class PushRuleStore(SQLBaseStore): new_rule['priority_class'] = priority_class new_rule['priority'] = new_prio + txn.call_after( + self.get_push_rules_for_user.invalidate, user_name + ) txn.call_after( self.get_push_rules_enabled_for_user.invalidate, user_name ) @@ -208,6 +217,8 @@ class PushRuleStore(SQLBaseStore): {'user_name': user_name, 'rule_id': rule_id}, desc="delete_push_rule", ) + + self.get_push_rules_for_user.invalidate(user_name) self.get_push_rules_enabled_for_user.invalidate(user_name) @defer.inlineCallbacks @@ -228,7 +239,12 @@ class PushRuleStore(SQLBaseStore): {'enabled': 1 if enabled else 0}, {'id': new_id}, ) - self.get_push_rules_enabled_for_user.invalidate(user_name) + txn.call_after( + self.get_push_rules_for_user.invalidate, user_name + ) + txn.call_after( + self.get_push_rules_enabled_for_user.invalidate, user_name + ) class RuleNotFoundException(Exception): -- cgit 1.4.1