Explorar el Código

Merge pull request #24993 from overleaf/bg-history-buffer-use-cache-in-persist-changes

use chunkBuffer in persistChanges

GitOrigin-RevId: dd4cdf39ba53c3becf306119fed7eacfe67de15d
Brian Gough hace 1 año
padre
commit
612981bedb

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

@@ -11,6 +11,7 @@ const History = core.History
 
 const assert = require('./assert')
 const chunkStore = require('./chunk_store')
+const chunkBuffer = require('./chunk_buffer')
 const { BlobStore } = require('./blob_store')
 const { InvalidChangeError } = require('./errors')
 const { getContentHash } = require('./content_hash')
@@ -180,7 +181,7 @@ async function persistChanges(projectId, allChanges, limits, clientEndVersion) {
   }
 
   async function extendLastChunkIfPossible() {
-    const latestChunk = await chunkStore.loadLatest(projectId)
+    const latestChunk = await chunkBuffer.loadLatest(projectId)
 
     currentChunk = latestChunk
     originalEndVersion = latestChunk.getEndVersion()

+ 6 - 1
services/history-v1/test/acceptance/js/api/project_updates.test.js

@@ -22,6 +22,7 @@ const TextOperation = core.TextOperation
 const V2DocVersions = core.V2DocVersions
 
 const knex = require('../../../../storage').knex
+const redis = require('../../../../storage/lib/chunk_store/redis')
 
 describe('history import', function () {
   beforeEach(cleanup.everything)
@@ -580,7 +581,7 @@ describe('history import', function () {
       .catch(expectResponse.unprocessableEntity)
       .then(getLatestContent)
       .then(response => {
-        // Check that no chaes were made
+        // Check that no changes were made
         const snapshot = Snapshot.fromRaw(response.obj)
         expect(snapshot.countFiles()).to.equal(1)
         expect(snapshot.getFile(mainFilePathname).getHash()).to.equal(
@@ -594,6 +595,10 @@ describe('history import', function () {
           testFiles.NULL_CHARACTERS_TXT_BYTE_LENGTH
         )
       })
+      .then(() => {
+        // Now clear the cache because we have changed the string length in the database
+        return redis.clearCache(testProjectId)
+      })
       .then(importChanges)
       .then(getLatestContent)
       .then(response => {