mirror of
https://github.com/element-hq/synapse.git
synced 2024-12-14 11:57:44 +00:00
Update the extremeties tables in a seperate txn
This commit is contained in:
parent
457970c724
commit
55ce9f9261
2 changed files with 74 additions and 61 deletions
|
@ -303,10 +303,13 @@ class EventFederationStore(SQLBaseStore):
|
|||
],
|
||||
)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def _update_extremeties(self, events):
|
||||
events_by_room = {}
|
||||
for ev in events:
|
||||
events_by_room.setdefault(ev.room_id, []).append(ev)
|
||||
|
||||
def _update_forwards_txn(txn):
|
||||
for room_id, room_events in events_by_room.items():
|
||||
prevs = [
|
||||
e_id for ev in room_events for e_id, _ in ev.prev_events
|
||||
|
@ -337,6 +340,7 @@ class EventFederationStore(SQLBaseStore):
|
|||
]
|
||||
)
|
||||
|
||||
def _update_backwards_txn(txn):
|
||||
query = (
|
||||
"INSERT INTO event_backward_extremities (event_id, room_id)"
|
||||
" SELECT ?, ? WHERE NOT EXISTS ("
|
||||
|
@ -372,6 +376,9 @@ class EventFederationStore(SQLBaseStore):
|
|||
self.get_latest_event_ids_in_room.invalidate, (room_id,)
|
||||
)
|
||||
|
||||
yield self.runInteraction("_update_forwards_txn", _update_forwards_txn)
|
||||
yield self.runInteraction("_update_backwards_txn", _update_backwards_txn)
|
||||
|
||||
def get_backfill_events(self, room_id, event_list, limit):
|
||||
"""Get a list of Events for a given topic that occurred before (and
|
||||
including) the events in event_list. Return a list of max size `limit`
|
||||
|
|
|
@ -86,6 +86,10 @@ class EventsStore(SQLBaseStore):
|
|||
is_new_state=is_new_state,
|
||||
)
|
||||
|
||||
yield self._update_extremeties([
|
||||
ev for ev, _ in chunk
|
||||
])
|
||||
|
||||
@defer.inlineCallbacks
|
||||
@log_function
|
||||
def persist_event(self, event, context, backfilled=False,
|
||||
|
@ -120,6 +124,8 @@ class EventsStore(SQLBaseStore):
|
|||
except _RollbackButIsFineException:
|
||||
pass
|
||||
|
||||
yield self._update_extremeties([event])
|
||||
|
||||
max_persisted_id = yield self._stream_id_gen.get_max_token(self)
|
||||
defer.returnValue((stream_ordering, max_persisted_id))
|
||||
|
||||
|
|
Loading…
Reference in a new issue