Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
WIP: Don't include the event we branch from
Browse files Browse the repository at this point in the history
We want to backfill all of the history before adding the base event.

But then there is a problem of how do we add the base event after
exhausting all of the historical messages. Backfill will give
us that extremity again but the current code will always
choose the historical branch over and over and never move past it.

I wish we could ask the federated homeserver if it already
has the insertion event locally but we can't make any requests
in the store code here :/
  • Loading branch information
MadLittleMods committed Oct 29, 2021
1 parent 4a12304 commit 9a6d8fa
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions synapse/storage/databases/main/event_federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,8 +1094,7 @@ def _get_backfill_events(self, txn, room_id, event_list, limit):
if event_id in event_results:
continue

event_results.add(event_id)

found_connected_historical_messages = False
if self.hs.config.experimental.msc2716_enabled:
# Try and find any potential historical batches of message history.
#
Expand All @@ -1117,7 +1116,9 @@ def _get_backfill_events(self, txn, room_id, event_list, limit):
connected_insertion_event_stream_ordering = row[1]
connected_insertion_event_id = row[2]
connected_insertion_event_type = row[3]

if connected_insertion_event_id not in event_results:
found_connected_historical_messages = True
queue.put(
(
-connected_insertion_event_depth,
Expand Down Expand Up @@ -1146,18 +1147,26 @@ def _get_backfill_events(self, txn, room_id, event_list, limit):
if row[2] not in event_results:
queue.put((-row[0], -row[1], row[2], row[3]))

txn.execute(
connected_prev_event_query,
(event_id, False, limit - len(event_results)),
)
prev_event_id_results = txn.fetchall()
logger.debug(
"_get_backfill_events: prev_event_ids %s", prev_event_id_results
)
# Only add the event_result itself if we didn't branch off on the history first
# TODO: How can we not branch off to the historical batch if
# the federated homeserver already has it backfilled? We
# can't make any requests here (no async stuff and should
# really only be database calls)
if not found_connected_historical_messages:
event_results.add(event_id)

txn.execute(
connected_prev_event_query,
(event_id, False, limit - len(event_results)),
)
prev_event_id_results = txn.fetchall()
logger.debug(
"_get_backfill_events: prev_event_ids %s", prev_event_id_results
)

for row in prev_event_id_results:
if row[2] not in event_results:
queue.put((-row[0], -row[1], row[2], row[3]))
for row in prev_event_id_results:
if row[2] not in event_results:
queue.put((-row[0], -row[1], row[2], row[3]))

return event_results

Expand Down

0 comments on commit 9a6d8fa

Please sign in to comment.