From 7f91e0c1bd4033de280268a4c657c9547fbb4af9 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Wed, 8 Sep 2021 15:43:02 -0700 Subject: [PATCH] Avoid simply incrementing fragment ID to get next fragment --- src/matrix/room/timeline/EventKey.ts | 5 ----- src/matrix/room/timeline/persistence/SyncWriter.js | 3 ++- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/matrix/room/timeline/EventKey.ts b/src/matrix/room/timeline/EventKey.ts index 8775df26..8f1e17da 100644 --- a/src/matrix/room/timeline/EventKey.ts +++ b/src/matrix/room/timeline/EventKey.ts @@ -25,11 +25,6 @@ export class EventKey { ) { } - nextFragmentKey(): EventKey { - // could take MIN_EVENT_INDEX here if it can't be paged back - return new EventKey(this.fragmentId + 1, KeyLimits.middleStorageKey); - } - nextKeyForDirection(direction: Direction): EventKey { if (direction.isForward) { return this.nextKey(); diff --git a/src/matrix/room/timeline/persistence/SyncWriter.js b/src/matrix/room/timeline/persistence/SyncWriter.js index 1ee2ce7d..8fd9d16a 100644 --- a/src/matrix/room/timeline/persistence/SyncWriter.js +++ b/src/matrix/room/timeline/persistence/SyncWriter.js @@ -124,7 +124,8 @@ export class SyncWriter { } else if (timeline.limited) { // replace live fragment for limited sync, *only* if we had a live fragment already const oldFragmentId = currentKey.fragmentId; - currentKey = currentKey.nextFragmentKey(); + const maxFragmentId = await txn.timelineFragments.getMaxFragmentId(this._roomId); + currentKey = EventKey.defaultFragmentKey(maxFragmentId + 1); const {oldFragment, newFragment} = await this._replaceLiveFragment(oldFragmentId, currentKey.fragmentId, timeline.prev_batch, txn); entries.push(FragmentBoundaryEntry.end(oldFragment, this._fragmentIdComparer)); entries.push(FragmentBoundaryEntry.start(newFragment, this._fragmentIdComparer));