pushers table requires a unique id.

This commit is contained in:
Erik Johnston 2015-04-15 16:24:14 +01:00
parent 806f380a8b
commit ed26e4012b
2 changed files with 11 additions and 3 deletions

View File

@ -260,6 +260,7 @@ class SQLBaseStore(object):
self._transaction_id_gen = IdGenerator("sent_transactions", "id", self)
self._state_groups_id_gen = IdGenerator("state_groups", "id", self)
self._access_tokens_id_gen = IdGenerator("access_tokens", "id", self)
self._pushers_id_gen = IdGenerator("pushers", "id", self)
def start_profiling(self):
self._previous_loop_ts = self._clock.time_msec()
@ -423,20 +424,22 @@ class SQLBaseStore(object):
txn.execute(sql, values.values())
def _simple_upsert(self, table, keyvalues, values, desc="_simple_upsert"):
def _simple_upsert(self, table, keyvalues, values,
insertion_values={}, desc="_simple_upsert"):
"""
Args:
table (str): The table to upsert into
keyvalues (dict): The unique key tables and their new values
values (dict): The nonunique columns and their new values
insertion_values (dict): key/values to use when inserting
Returns: A deferred
"""
return self.runInteraction(
desc,
self._simple_upsert_txn, table, keyvalues, values
self._simple_upsert_txn, table, keyvalues, values, insertion_values,
)
def _simple_upsert_txn(self, txn, table, keyvalues, values):
def _simple_upsert_txn(self, txn, table, keyvalues, values, insertion_values={}):
# Try to update
sql = "UPDATE %s SET %s WHERE %s" % (
table,
@ -455,6 +458,7 @@ class SQLBaseStore(object):
allvalues = {}
allvalues.update(keyvalues)
allvalues.update(values)
allvalues.update(insertion_values)
sql = "INSERT INTO %s (%s) VALUES (%s)" % (
table,

View File

@ -99,6 +99,7 @@ class PusherStore(SQLBaseStore):
app_display_name, device_display_name,
pushkey, pushkey_ts, lang, data):
try:
next_id = self._pushers_id_gen.get_next()
yield self._simple_upsert(
PushersTable.table_name,
dict(
@ -115,6 +116,9 @@ class PusherStore(SQLBaseStore):
lang=lang,
data=data
),
insertion_values=dict(
id=next_id,
),
desc="add_pusher",
)
except Exception as e: