From 21acae446355df81732f2f044da42f07b149cf96 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Thu, 24 Apr 2025 09:58:08 +0100 Subject: [PATCH] Merge pull request #24993 from overleaf/bg-history-buffer-use-cache-in-persist-changes use chunkBuffer in persistChanges GitOrigin-RevId: dd4cdf39ba53c3becf306119fed7eacfe67de15d --- services/history-v1/storage/lib/persist_changes.js | 3 ++- .../test/acceptance/js/api/project_updates.test.js | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/services/history-v1/storage/lib/persist_changes.js b/services/history-v1/storage/lib/persist_changes.js index 8a848aa214..2000bc6cbd 100644 --- a/services/history-v1/storage/lib/persist_changes.js +++ b/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() diff --git a/services/history-v1/test/acceptance/js/api/project_updates.test.js b/services/history-v1/test/acceptance/js/api/project_updates.test.js index d67000245a..eb7b1703a7 100644 --- a/services/history-v1/test/acceptance/js/api/project_updates.test.js +++ b/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 => {