Fix clearing out old device list outbound pokes

This commit is contained in:
Erik Johnston 2017-01-31 10:08:55 +00:00
parent 1c13c9f6b6
commit 05b9f48ee5
1 changed files with 7 additions and 2 deletions

View File

@ -545,7 +545,7 @@ class DeviceStore(SQLBaseStore):
(destination, user_id) tuple to ensure that the prev_ids remain correct (destination, user_id) tuple to ensure that the prev_ids remain correct
if the server does come back. if the server does come back.
""" """
now = self._clock.time_msec() yesterday = self._clock.time_msec() - 24 * 60 * 60 * 1000
def _prune_txn(txn): def _prune_txn(txn):
select_sql = """ select_sql = """
@ -557,6 +557,9 @@ class DeviceStore(SQLBaseStore):
txn.execute(select_sql) txn.execute(select_sql)
rows = txn.fetchall() rows = txn.fetchall()
if not rows:
return
delete_sql = """ delete_sql = """
DELETE FROM device_lists_outbound_pokes DELETE FROM device_lists_outbound_pokes
WHERE ts < ? AND destination = ? AND user_id = ? AND stream_id < ? WHERE ts < ? AND destination = ? AND user_id = ? AND stream_id < ?
@ -565,11 +568,13 @@ class DeviceStore(SQLBaseStore):
txn.executemany( txn.executemany(
delete_sql, delete_sql,
( (
(now, row["destination"], row["user_id"], row["stream_id"]) (yesterday, row[0], row[1], row[2])
for row in rows for row in rows
) )
) )
logger.info("Pruned %d device list outbound pokes", txn.rowcount)
return self.runInteraction( return self.runInteraction(
"_prune_old_outbound_device_pokes", _prune_txn "_prune_old_outbound_device_pokes", _prune_txn
) )