From 53447e9cd380262c16677cfddeda1d75aeebe38c Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Thu, 21 May 2015 15:14:26 +0100 Subject: Add caches for things requested by the pushers --- synapse/storage/push_rule.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'synapse/storage/push_rule.py') diff --git a/synapse/storage/push_rule.py b/synapse/storage/push_rule.py index 34805e276e..fba5c7e403 100644 --- a/synapse/storage/push_rule.py +++ b/synapse/storage/push_rule.py @@ -13,9 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import collections - -from ._base import SQLBaseStore, Table +from ._base import SQLBaseStore, cached from twisted.internet import defer import logging @@ -41,6 +39,7 @@ class PushRuleStore(SQLBaseStore): defer.returnValue(rows) + @cached() @defer.inlineCallbacks def get_push_rules_enabled_for_user(self, user_name): results = yield self._simple_select_list( @@ -151,6 +150,10 @@ class PushRuleStore(SQLBaseStore): txn.execute(sql, (user_name, priority_class, new_rule_priority)) + txn.call_after( + self.get_push_rules_enabled_for_user.invalidate, user_name + ) + self._simple_insert_txn( txn, table=PushRuleTable.table_name, @@ -179,6 +182,10 @@ class PushRuleStore(SQLBaseStore): new_rule['priority_class'] = priority_class new_rule['priority'] = new_prio + txn.call_after( + self.get_push_rules_enabled_for_user.invalidate, user_name + ) + self._simple_insert_txn( txn, table=PushRuleTable.table_name, @@ -201,6 +208,7 @@ class PushRuleStore(SQLBaseStore): {'user_name': user_name, 'rule_id': rule_id}, desc="delete_push_rule", ) + self.get_push_rules_enabled_for_user.invalidate(user_name) @defer.inlineCallbacks def set_push_rule_enabled(self, user_name, rule_id, enabled): @@ -210,6 +218,9 @@ class PushRuleStore(SQLBaseStore): {'enabled': 1 if enabled else 0}, desc="set_push_rule_enabled", ) + txn.call_after( + self.get_push_rules_enabled_for_user.invalidate, user_name + ) class RuleNotFoundException(Exception): @@ -220,7 +231,7 @@ class InconsistentRuleException(Exception): pass -class PushRuleTable(Table): +class PushRuleTable(object): table_name = "push_rules" fields = [ @@ -233,10 +244,8 @@ class PushRuleTable(Table): "actions", ] - EntryType = collections.namedtuple("PushRuleEntry", fields) - -class PushRuleEnableTable(Table): +class PushRuleEnableTable(object): table_name = "push_rules_enable" fields = [ -- cgit 1.4.1 From 2043527b9bbea019b8a4ffddcc9e82438d12b1d5 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Thu, 21 May 2015 16:53:03 +0100 Subject: Don't try to use a txn when not in one, remove spurious debug logging --- synapse/push/__init__.py | 2 -- synapse/storage/push_rule.py | 4 +--- 2 files changed, 1 insertion(+), 5 deletions(-) (limited to 'synapse/storage/push_rule.py') diff --git a/synapse/push/__init__.py b/synapse/push/__init__.py index d4b376913c..e3dd4ce76d 100644 --- a/synapse/push/__init__.py +++ b/synapse/push/__init__.py @@ -287,8 +287,6 @@ class Pusher(object): logger.warn("Neither notify nor dont_notify in actions: adding default") actions.extend(Pusher.DEFAULT_ACTIONS) - logger.info("FNARG: %r", actions) - if 'dont_notify' in actions: logger.debug( "%s for %s: dont_notify", diff --git a/synapse/storage/push_rule.py b/synapse/storage/push_rule.py index fba5c7e403..88ee21b089 100644 --- a/synapse/storage/push_rule.py +++ b/synapse/storage/push_rule.py @@ -218,9 +218,7 @@ class PushRuleStore(SQLBaseStore): {'enabled': 1 if enabled else 0}, desc="set_push_rule_enabled", ) - txn.call_after( - self.get_push_rules_enabled_for_user.invalidate, user_name - ) + self.get_push_rules_enabled_for_user.invalidate(user_name) class RuleNotFoundException(Exception): -- cgit 1.4.1