Sfoglia il codice sorgente

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

correct startVersion calculation in loadAtTimestamp

GitOrigin-RevId: ad46aae47c0769943e787199d68e895cf139bb56
Brian Gough 1 anno fa
parent
commit
2d0706591b

+ 2 - 1
services/history-v1/storage/lib/chunk_store/index.js

@@ -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)
 }
 
 /**

+ 6 - 0
services/history-v1/test/acceptance/js/storage/chunk_store.test.js

@@ -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 () {