diff options
author | Erik Johnston <erik@matrix.org> | 2015-05-12 14:41:50 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2015-05-12 14:41:50 +0100 |
commit | c1779a79bc6da69621d0034e582008e95db02dad (patch) | |
tree | 76540f000534774c090d50bc8ff49cda1fd80117 /synapse/storage/event_federation.py | |
parent | Do state groups persistence /after/ checking if we have already persisted the... (diff) | |
download | synapse-c1779a79bc6da69621d0034e582008e95db02dad.tar.xz |
Fix up _handle_prev_events to not try to insert duplicate rows
Diffstat (limited to 'synapse/storage/event_federation.py')
-rw-r--r-- | synapse/storage/event_federation.py | 36 |
1 files changed, 13 insertions, 23 deletions
diff --git a/synapse/storage/event_federation.py b/synapse/storage/event_federation.py index 2b5424ced4..6773e44688 100644 --- a/synapse/storage/event_federation.py +++ b/synapse/storage/event_federation.py @@ -330,31 +330,21 @@ class EventFederationStore(SQLBaseStore): txn.execute(query, (event_id, room_id)) - # Insert all the prev_events as a backwards thing, they'll get - # deleted in a second if they're incorrect anyway. - self._simple_insert_many_txn( - txn, - table="event_backward_extremities", - values=[ - { - "event_id": e_id, - "room_id": room_id, - } - for e_id, _ in prev_events - ], - ) - - # Also delete from the backwards extremities table all ones that - # reference events that we have already seen query = ( - "DELETE FROM event_backward_extremities WHERE EXISTS (" - "SELECT 1 FROM events " - "WHERE " - "event_backward_extremities.event_id = events.event_id " - "AND not events.outlier " - ")" + "INSERT INTO event_backward_extremities (event_id, room_id)" + " SELECT ?, ? WHERE NOT EXISTS (" + " SELECT 1 FROM event_backward_extremities" + " WHERE event_id = ? AND room_id = ?" + " )" + " AND NOT EXISTS (" + " SELECT 1 FROM events WHERE event_id = ? AND room_id = ?" + " )" ) - txn.execute(query) + + txn.executemany(query, [ + (e_id, room_id, e_id, room_id, e_id, room_id,) + for e_id, _ in prev_events + ]) txn.call_after( self.get_latest_event_ids_in_room.invalidate, room_id |