mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-03 14:19:01 +02:00
Merge pull request #27126 from overleaf/em-fix-persist-changes
Fix chunk creation over a one change chunk GitOrigin-RevId: aecae334849522975b83c77224ee27db64de4ed8
This commit is contained in:
@@ -246,7 +246,7 @@ async function create(projectId, chunk, earliestChangeTimestamp) {
|
||||
|
||||
const opts = {}
|
||||
if (chunkStart > 0) {
|
||||
const oldChunk = await backend.getChunkForVersion(projectId, chunkStart - 1)
|
||||
const oldChunk = await backend.getChunkForVersion(projectId, chunkStart)
|
||||
|
||||
if (oldChunk.endVersion !== chunkStart) {
|
||||
throw new ChunkVersionConflictError(
|
||||
|
||||
@@ -8,6 +8,7 @@ const { ObjectId } = require('mongodb')
|
||||
const { projects } = require('../../../../storage/lib/mongodb')
|
||||
const {
|
||||
ChunkVersionConflictError,
|
||||
VersionNotFoundError,
|
||||
} = require('../../../../storage/lib/chunk_store/errors')
|
||||
|
||||
const {
|
||||
@@ -396,7 +397,7 @@ describe('chunkStore', function () {
|
||||
const newChunk = makeChunk([change], 7)
|
||||
await expect(
|
||||
chunkStore.create(projectId, newChunk)
|
||||
).to.be.rejectedWith(ChunkVersionConflictError)
|
||||
).to.be.rejectedWith(VersionNotFoundError)
|
||||
const latestChunk = await chunkStore.loadLatest(projectId)
|
||||
expect(latestChunk.toRaw()).to.deep.equal(thirdChunk.toRaw())
|
||||
})
|
||||
|
||||
@@ -67,7 +67,7 @@ describe('persistChanges', function () {
|
||||
expect(chunk.getChanges().length).to.equal(1)
|
||||
})
|
||||
|
||||
it('persists changes in two chunks', async function () {
|
||||
it('persists changes in three chunks', async function () {
|
||||
const limitsToPersistImmediately = {
|
||||
maxChunkChanges: 1,
|
||||
minChangeTimestamp: farFuture,
|
||||
@@ -84,7 +84,12 @@ describe('persistChanges', function () {
|
||||
new Date(),
|
||||
[]
|
||||
)
|
||||
const changes = [firstChange, secondChange]
|
||||
const thirdChange = new Change(
|
||||
[new AddFileOperation('c.tex', File.fromString(''))],
|
||||
new Date(),
|
||||
[]
|
||||
)
|
||||
const changes = [firstChange, secondChange, thirdChange]
|
||||
|
||||
await chunkStore.initializeProject(projectId)
|
||||
const result = await persistChanges(
|
||||
@@ -99,20 +104,23 @@ describe('persistChanges', function () {
|
||||
'a.tex': {
|
||||
content: '',
|
||||
},
|
||||
'b.tex': {
|
||||
content: '',
|
||||
},
|
||||
},
|
||||
})
|
||||
const history = new History(snapshot, [secondChange])
|
||||
const currentChunk = new Chunk(history, 1)
|
||||
const history = new History(snapshot, [thirdChange])
|
||||
const currentChunk = new Chunk(history, 2)
|
||||
expect(result).to.deep.equal({
|
||||
numberOfChangesPersisted: 2,
|
||||
numberOfChangesPersisted: 3,
|
||||
originalEndVersion: 0,
|
||||
currentChunk,
|
||||
resyncNeeded: false,
|
||||
})
|
||||
|
||||
const chunk = await chunkStore.loadLatest(projectId)
|
||||
expect(chunk.getStartVersion()).to.equal(1)
|
||||
expect(chunk.getEndVersion()).to.equal(2)
|
||||
expect(chunk.getStartVersion()).to.equal(2)
|
||||
expect(chunk.getEndVersion()).to.equal(3)
|
||||
expect(chunk.getChanges().length).to.equal(1)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user