Fixup add_pusher

This commit is contained in:
Erik Johnston 2016-05-13 11:25:02 +01:00
parent 260b498ee5
commit 13d37c3c56
2 changed files with 17 additions and 4 deletions

View File

@ -453,7 +453,9 @@ class SQLBaseStore(object):
keyvalues (dict): The unique key tables and their new values keyvalues (dict): The unique key tables and their new values
values (dict): The nonunique columns and their new values values (dict): The nonunique columns and their new values
insertion_values (dict): key/values to use when inserting insertion_values (dict): key/values to use when inserting
Returns: A deferred Returns:
Deferred(bool): True if a new entry was created, False if an
exisitng one was updated.
""" """
return self.runInteraction( return self.runInteraction(
desc, desc,
@ -498,6 +500,10 @@ class SQLBaseStore(object):
) )
txn.execute(sql, allvalues.values()) txn.execute(sql, allvalues.values())
return True
else:
return False
def _simple_select_one(self, table, keyvalues, retcols, def _simple_select_one(self, table, keyvalues, retcols,
allow_none=False, desc="_simple_select_one"): allow_none=False, desc="_simple_select_one"):
"""Executes a SELECT query on the named table, which is expected to """Executes a SELECT query on the named table, which is expected to

View File

@ -156,8 +156,7 @@ class PusherStore(SQLBaseStore):
profile_tag=""): profile_tag=""):
with self._pushers_id_gen.get_next() as stream_id: with self._pushers_id_gen.get_next() as stream_id:
def f(txn): def f(txn):
txn.call_after(self.get_users_with_pushers_in_room.invalidate_all) newly_inserted = self._simple_upsert_txn(
return self._simple_upsert_txn(
txn, txn,
"pushers", "pushers",
{ {
@ -178,11 +177,18 @@ class PusherStore(SQLBaseStore):
"id": stream_id, "id": stream_id,
}, },
) )
defer.returnValue((yield self.runInteraction("add_pusher", f))) if newly_inserted:
# get_users_with_pushers_in_room only cares if the user has
# at least *one* pusher.
txn.call_after(self.get_users_with_pushers_in_room.invalidate_all)
yield self.runInteraction("add_pusher", f)
@defer.inlineCallbacks @defer.inlineCallbacks
def delete_pusher_by_app_id_pushkey_user_id(self, app_id, pushkey, user_id): def delete_pusher_by_app_id_pushkey_user_id(self, app_id, pushkey, user_id):
def delete_pusher_txn(txn, stream_id): def delete_pusher_txn(txn, stream_id):
txn.call_after(self.get_users_with_pushers_in_room.invalidate_all)
self._simple_delete_one_txn( self._simple_delete_one_txn(
txn, txn,
"pushers", "pushers",
@ -194,6 +200,7 @@ class PusherStore(SQLBaseStore):
{"app_id": app_id, "pushkey": pushkey, "user_id": user_id}, {"app_id": app_id, "pushkey": pushkey, "user_id": user_id},
{"stream_id": stream_id}, {"stream_id": stream_id},
) )
with self._pushers_id_gen.get_next() as stream_id: with self._pushers_id_gen.get_next() as stream_id:
yield self.runInteraction( yield self.runInteraction(
"delete_pusher", delete_pusher_txn, stream_id "delete_pusher", delete_pusher_txn, stream_id