mirror of
https://github.com/element-hq/synapse
synced 2024-09-28 16:32:40 +00:00
Separate backward extremity insertion for re-use
This commit is contained in:
parent
6cba6a51af
commit
74e676256e
2 changed files with 44 additions and 10 deletions
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue