Merge pull request #26219 from overleaf/bg-history-redis-fix-loadAtTimestamp

correct startVersion calculation in loadAtTimestamp

GitOrigin-RevId: ad46aae47c0769943e787199d68e895cf139bb56
This commit is contained in:
Brian Gough
2025-06-10 10:41:55 +01:00
committed by Copybot
parent 4c383f1496
commit 96a278f8ad
2 changed files with 8 additions and 1 deletions
@@ -190,6 +190,7 @@ async function loadAtTimestamp(projectId, timestamp, opts = {}) {
const chunkRecord = await backend.getChunkForTimestamp(projectId, timestamp)
const rawHistory = await historyStore.loadRaw(projectId, chunkRecord.id)
const history = History.fromRaw(rawHistory)
const startVersion = chunkRecord.endVersion - history.countChanges()
if (!opts.persistedOnly) {
const nonPersistedChanges = await getChunkExtension(
@@ -200,7 +201,7 @@ async function loadAtTimestamp(projectId, timestamp, opts = {}) {
}
await lazyLoadHistoryFiles(history, batchBlobStore)
return new Chunk(history, chunkRecord.endVersion - history.countChanges())
return new Chunk(history, startVersion)
}
/**
@@ -509,6 +509,12 @@ describe('chunkStore', function () {
.getChanges()
.concat(queuedChanges)
expect(chunk.getChanges()).to.deep.equal(expectedChanges)
expect(chunk.getStartVersion()).to.equal(
thirdChunk.getStartVersion()
)
expect(chunk.getEndVersion()).to.equal(
thirdChunk.getEndVersion() + queuedChanges.length
)
})
it("doesn't include the queued changes when getting another chunk by timestamp", async function () {