diff options
author | Eric Eastwood <erice@element.io> | 2022-06-29 20:53:34 +0200 |
---|---|---|
committer | Eric Eastwood <erice@element.io> | 2022-06-29 20:53:34 +0200 |
commit | 74e676256ef2494558a136dcc48ac2b689e25f6d (patch) | |
tree | 54ccd4e3032da82394f7a8db99f666532d0541a5 | |
parent | Merge branch 'master' into develop (diff) | |
download | synapse-github/madlittlemods/msc3030-backfill-at-remote-event-fetched.tar.xz |
Separate backward extremity insertion for re-use github/madlittlemods/msc3030-backfill-at-remote-event-fetched madlittlemods/msc3030-backfill-at-remote-event-fetched
-rw-r--r-- | synapse/handlers/room.py | 5 | ||||
-rw-r--r-- | synapse/storage/databases/main/events.py | 49 |
2 files changed, 44 insertions, 10 deletions
diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index 75c0be8c36..a151b6ecd8 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -1427,7 +1427,6 @@ class TimestampLookupHandler: remote_response, ) - # TODO: Do we want to persist this as an extremity? # TODO: I think ideally, we would try to backfill from # this event and run this whole # `get_event_for_timestamp` function again to make sure @@ -1435,6 +1434,10 @@ class TimestampLookupHandler: remote_event_id = remote_response.event_id origin_server_ts = remote_response.origin_server_ts + # Persist this as an extremity so we can backfill from it + # later when calling `/messages` + self.store.insert_backward_extremeties([(room_id, remote_event_id)]) + # Only return the remote event if it's closer than the local event if not local_event or ( abs(origin_server_ts - timestamp) diff --git a/synapse/storage/databases/main/events.py b/synapse/storage/databases/main/events.py index a3e12f1e9b..33b74e3942 100644 --- a/synapse/storage/databases/main/events.py +++ b/synapse/storage/databases/main/events.py @@ -2304,18 +2304,28 @@ class PersistEventsStore: self._update_backward_extremeties(txn, events) - def _update_backward_extremeties( - self, txn: LoggingTransaction, events: List[EventBase] + async def insert_backward_extremeties( + self, room_id_and_event_id_pairs: List[Tuple[str, str]] ) -> None: - """Updates the event_backward_extremities tables based on the new/updated - events being persisted. + """TODO - This is called for new events *and* for events that were outliers, but - are now being persisted as non-outliers. + Args: + room_and_event_id_pairs: Events to mark as backward extremities - Forward extremities are handled when we first start persisting the events. + Returns: + xxx """ - # From the events passed in, add all of the prev events as backwards extremities. + + return await self.db_pool.runInteraction( + "_insert_backward_extremeties_txn", + self._insert_backward_extremeties_txn, + ) + + def _insert_backward_extremeties_txn( + txn: LoggingTransaction, room_id_and_event_id_pairs: List[Tuple[str, str]] + ) -> None: + """TODO""" + # Ignore any events that are already backwards extrems or outliers. query = ( "INSERT INTO event_backward_extremities (event_id, room_id)" @@ -2337,7 +2347,28 @@ class PersistEventsStore: txn.execute_batch( query, [ - (e_id, ev.room_id, e_id, ev.room_id, e_id, ev.room_id, False) + (event_id, room_id, event_id, room_id, event_id, room_id, False) + for (room_id, event_id) in room_id_and_event_id_pairs + ], + ) + + def _update_backward_extremeties( + self, txn: LoggingTransaction, events: List[EventBase] + ) -> None: + """Updates the event_backward_extremities tables based on the new/updated + events being persisted. + + This is called for new events *and* for events that were outliers, but + are now being persisted as non-outliers. + + Forward extremities are handled when we first start persisting the events. + """ + # From the events passed in, add all of the prev events as backwards extremities. + # Ignore any events that are already backwards extrems or outliers. + self._insert_backward_extremeties_txn( + txn, + [ + (ev.room_id, e_id) for ev in events for e_id in ev.prev_event_ids() if not ev.internal_metadata.is_outlier() |