mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-25 18:20:09 +02:00
Merge pull request #23345 from overleaf/bg-write-latest-history-version-to-project
update project entry with history metadata on chunk creation GitOrigin-RevId: dd19898f3d16e2e3360ff1bcccbf79f7dd27addb
This commit is contained in:
@@ -153,6 +153,30 @@ async function confirmCreate(projectId, chunk, chunkId, mongoOpts = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the metadata to the project record
|
||||
*/
|
||||
async function updateProjectRecord(projectId, chunk, mongoOpts = {}) {
|
||||
// record the end version against the project
|
||||
await mongodb.projects.updateOne(
|
||||
{
|
||||
'overleaf.history.id': projectId, // string for Object ids, number for postgres ids
|
||||
},
|
||||
{
|
||||
// always store the latest end version and timestamp for the chunk
|
||||
$max: {
|
||||
'overleaf.history.currentEndVersion': chunk.getEndVersion(),
|
||||
'overleaf.history.currentEndTimestamp': chunk.getEndTimestamp(),
|
||||
'overleaf.history.updatedAt': new Date(),
|
||||
},
|
||||
// store the first pending change timestamp for the chunk, this will
|
||||
// be cleared every time a backup is completed.
|
||||
$min: { 'overleaf.backup.pendingChangeAt': chunk.getEndTimestamp() },
|
||||
},
|
||||
mongoOpts
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Record that a chunk was replaced by a new one.
|
||||
*/
|
||||
@@ -167,6 +191,7 @@ async function confirmUpdate(projectId, oldChunkId, newChunk, newChunkId) {
|
||||
await session.withTransaction(async () => {
|
||||
await deleteChunk(projectId, oldChunkId, { session })
|
||||
await confirmCreate(projectId, newChunk, newChunkId, { session })
|
||||
await updateProjectRecord(projectId, newChunk, { session })
|
||||
})
|
||||
} finally {
|
||||
await session.endSession()
|
||||
@@ -273,6 +298,7 @@ module.exports = {
|
||||
insertPendingChunk,
|
||||
confirmCreate,
|
||||
confirmUpdate,
|
||||
updateProjectRecord,
|
||||
deleteChunk,
|
||||
deleteProjectChunks,
|
||||
getOldChunksBatch,
|
||||
|
||||
@@ -3,6 +3,7 @@ const assert = require('../assert')
|
||||
const knex = require('../knex')
|
||||
const knexReadOnly = require('../knex_read_only')
|
||||
const { ChunkVersionConflictError } = require('./errors')
|
||||
const { updateProjectRecord } = require('./mongo')
|
||||
|
||||
const DUPLICATE_KEY_ERROR_CODE = '23505'
|
||||
|
||||
@@ -150,6 +151,7 @@ async function confirmUpdate(projectId, oldChunkId, newChunk, newChunkId) {
|
||||
_deletePendingChunk(tx, projectId, newChunkId),
|
||||
_insertChunk(tx, projectId, newChunk, newChunkId),
|
||||
])
|
||||
await updateProjectRecord(projectId, newChunk)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user