mirror of
https://github.com/element-hq/synapse
synced 2024-09-29 17:02:41 +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,
|
remote_response,
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: Do we want to persist this as an extremity?
|
|
||||||
# TODO: I think ideally, we would try to backfill from
|
# TODO: I think ideally, we would try to backfill from
|
||||||
# this event and run this whole
|
# this event and run this whole
|
||||||
# `get_event_for_timestamp` function again to make sure
|
# `get_event_for_timestamp` function again to make sure
|
||||||
|
@ -1435,6 +1434,10 @@ class TimestampLookupHandler:
|
||||||
remote_event_id = remote_response.event_id
|
remote_event_id = remote_response.event_id
|
||||||
origin_server_ts = remote_response.origin_server_ts
|
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
|
# Only return the remote event if it's closer than the local event
|
||||||
if not local_event or (
|
if not local_event or (
|
||||||
abs(origin_server_ts - timestamp)
|
abs(origin_server_ts - timestamp)
|
||||||
|
|
|
@ -2304,18 +2304,28 @@ class PersistEventsStore:
|
||||||
|
|
||||||
self._update_backward_extremeties(txn, events)
|
self._update_backward_extremeties(txn, events)
|
||||||
|
|
||||||
def _update_backward_extremeties(
|
async def insert_backward_extremeties(
|
||||||
self, txn: LoggingTransaction, events: List[EventBase]
|
self, room_id_and_event_id_pairs: List[Tuple[str, str]]
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Updates the event_backward_extremities tables based on the new/updated
|
"""TODO
|
||||||
events being persisted.
|
|
||||||
|
|
||||||
This is called for new events *and* for events that were outliers, but
|
Args:
|
||||||
are now being persisted as non-outliers.
|
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.
|
# Ignore any events that are already backwards extrems or outliers.
|
||||||
query = (
|
query = (
|
||||||
"INSERT INTO event_backward_extremities (event_id, room_id)"
|
"INSERT INTO event_backward_extremities (event_id, room_id)"
|
||||||
|
@ -2337,7 +2347,28 @@ class PersistEventsStore:
|
||||||
txn.execute_batch(
|
txn.execute_batch(
|
||||||
query,
|
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 ev in events
|
||||||
for e_id in ev.prev_event_ids()
|
for e_id in ev.prev_event_ids()
|
||||||
if not ev.internal_metadata.is_outlier()
|
if not ev.internal_metadata.is_outlier()
|
||||||
|
|
Loading…
Reference in a new issue