From df273c5e2c2846ea5ec0125af0c1239deafea031 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 14 Sep 2021 15:40:15 -0700 Subject: [PATCH] Store more events from backfill --- .../room/timeline/persistence/GapWriter.js | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/matrix/room/timeline/persistence/GapWriter.js b/src/matrix/room/timeline/persistence/GapWriter.js index 1a40f23e..f5108f3c 100644 --- a/src/matrix/room/timeline/persistence/GapWriter.js +++ b/src/matrix/room/timeline/persistence/GapWriter.js @@ -47,28 +47,30 @@ export class GapWriter { } nonOverlappingEvents.push(...remainingEvents.slice(0, duplicateEventIndex)); if (!expectedOverlappingEventId || duplicateEventId === expectedOverlappingEventId) { - // TODO: check here that the neighbourEvent is at the correct edge of it's fragment - // get neighbour fragment to link it up later on - const neighbourEvent = await txn.timelineEvents.getByEventId(this._roomId, duplicateEventId); - if (neighbourEvent.fragmentId === fragmentEntry.fragmentId) { - log.log("hit #160, prevent fragment linking to itself", log.level.Warn); - } else { + // Only link fragment if this is the first overlapping fragment we discover. + // TODO is this sufficient? Might we get "out of order" fragments from events? + if (!neighbourFragmentEntry) { + // TODO: check here that the neighbourEvent is at the correct edge of it's fragment + // get neighbour fragment to link it up later on + const neighbourEvent = await txn.timelineEvents.getByEventId(this._roomId, duplicateEventId); const neighbourFragment = await txn.timelineFragments.get(this._roomId, neighbourEvent.fragmentId); neighbourFragmentEntry = fragmentEntry.createNeighbourEntry(neighbourFragment); } - // trim overlapping events - remainingEvents = null; - } else { - // we've hit https://github.com/matrix-org/synapse/issues/7164, - // e.g. the event id we found is already in our store but it is not - // the adjacent fragment id. Ignore the event, but keep processing the ones after. - remainingEvents = remainingEvents.slice(duplicateEventIndex + 1); - } + } + // If more events remain, or if this wasn't the expected overlapping event, + // we've hit https://github.com/matrix-org/synapse/issues/7164, + // e.g. the event id we found is already in our store but it is not + // the adjacent fragment id. Ignore the event, but keep processing the ones after. + remainingEvents = remainingEvents.slice(duplicateEventIndex + 1); } else { nonOverlappingEvents.push(...remainingEvents); remainingEvents = null; } } + if (neighbourFragmentEntry?.fragmentId === fragmentEntry.fragmentId) { + log.log("hit #160, prevent fragment linking to itself", log.level.Warn); + neighbourFragmentEntry = null; + } return {nonOverlappingEvents, neighbourFragmentEntry}; }