mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-04 14:49:01 +02:00
Merge pull request #26545 from overleaf/jpa-fix-resync
[history-v1] use mongo projectId for initiating resync GitOrigin-RevId: f93f2358695782fb222d23ba3720d98724b9a291
This commit is contained in:
@@ -286,6 +286,27 @@ async function updateProjectRecord(
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} historyId
|
||||
* @return {Promise<string>}
|
||||
*/
|
||||
async function lookupMongoProjectIdFromHistoryId(historyId) {
|
||||
const project = await mongodb.projects.findOne(
|
||||
// string for Object ids, number for postgres ids
|
||||
{ 'overleaf.history.id': historyId },
|
||||
{ projection: { _id: 1 } }
|
||||
)
|
||||
if (!project) {
|
||||
// should not happen: We flush before allowing a project to be soft-deleted.
|
||||
throw new OError('mongo project not found by history id', { historyId })
|
||||
}
|
||||
return project._id.toString()
|
||||
}
|
||||
|
||||
async function resolveHistoryIdToMongoProjectId(projectId) {
|
||||
return projectId
|
||||
}
|
||||
|
||||
/**
|
||||
* Record that a chunk was replaced by a new one.
|
||||
*
|
||||
@@ -533,4 +554,6 @@ module.exports = {
|
||||
deleteProjectChunks,
|
||||
getOldChunksBatch,
|
||||
deleteOldChunks,
|
||||
lookupMongoProjectIdFromHistoryId,
|
||||
resolveHistoryIdToMongoProjectId,
|
||||
}
|
||||
|
||||
@@ -5,7 +5,10 @@ const assert = require('../assert')
|
||||
const knex = require('../knex')
|
||||
const knexReadOnly = require('../knex_read_only')
|
||||
const { ChunkVersionConflictError } = require('./errors')
|
||||
const { updateProjectRecord } = require('./mongo')
|
||||
const {
|
||||
updateProjectRecord,
|
||||
lookupMongoProjectIdFromHistoryId,
|
||||
} = require('./mongo')
|
||||
|
||||
const DUPLICATE_KEY_ERROR_CODE = '23505'
|
||||
|
||||
@@ -472,6 +475,10 @@ async function generateProjectId() {
|
||||
return record.doc_id.toString()
|
||||
}
|
||||
|
||||
async function resolveHistoryIdToMongoProjectId(projectId) {
|
||||
return await lookupMongoProjectIdFromHistoryId(parseInt(projectId, 10))
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getLatestChunk,
|
||||
getFirstChunkBeforeTimestamp,
|
||||
@@ -488,4 +495,5 @@ module.exports = {
|
||||
getOldChunksBatch,
|
||||
deleteOldChunks,
|
||||
generateProjectId,
|
||||
resolveHistoryIdToMongoProjectId,
|
||||
}
|
||||
|
||||
@@ -186,7 +186,10 @@ async function persistBuffer(projectId, limits) {
|
||||
'content hash validation failed while persisting a history resync, skipping additional resync'
|
||||
)
|
||||
} else {
|
||||
await resyncProject(projectId)
|
||||
const backend = chunkStore.getBackend(projectId)
|
||||
const mongoProjectId =
|
||||
await backend.resolveHistoryIdToMongoProjectId(projectId)
|
||||
await resyncProject(mongoProjectId)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user