Fix up _handle_prev_events to not try to insert duplicate rows

This commit is contained in:
Erik Johnston 2015-05-12 14:41:50 +01:00
parent 74850d7f75
commit c1779a79bc
1 changed files with 13 additions and 23 deletions

View File

@ -330,31 +330,21 @@ class EventFederationStore(SQLBaseStore):
txn.execute(query, (event_id, room_id)) txn.execute(query, (event_id, room_id))
# Insert all the prev_events as a backwards thing, they'll get query = (
# deleted in a second if they're incorrect anyway. "INSERT INTO event_backward_extremities (event_id, room_id)"
self._simple_insert_many_txn( " SELECT ?, ? WHERE NOT EXISTS ("
txn, " SELECT 1 FROM event_backward_extremities"
table="event_backward_extremities", " WHERE event_id = ? AND room_id = ?"
values=[ " )"
{ " AND NOT EXISTS ("
"event_id": e_id, " SELECT 1 FROM events WHERE event_id = ? AND room_id = ?"
"room_id": room_id, " )"
}
for e_id, _ in prev_events
],
) )
# Also delete from the backwards extremities table all ones that txn.executemany(query, [
# reference events that we have already seen (e_id, room_id, e_id, room_id, e_id, room_id,)
query = ( for e_id, _ in prev_events
"DELETE FROM event_backward_extremities WHERE EXISTS (" ])
"SELECT 1 FROM events "
"WHERE "
"event_backward_extremities.event_id = events.event_id "
"AND not events.outlier "
")"
)
txn.execute(query)
txn.call_after( txn.call_after(
self.get_latest_event_ids_in_room.invalidate, room_id self.get_latest_event_ids_in_room.invalidate, room_id