Merge pull request #15648 from overleaf/em-promisify-doc-manager

Promisify DocManager

GitOrigin-RevId: c9ab368086492900e1617d5d96943d405f25883d
This commit is contained in:
Eric Mc Sween
2023-11-09 09:03:10 +00:00
committed by Copybot
parent 292e9efbb7
commit f397d79439
7 changed files with 598 additions and 864 deletions
+28 -28
View File
@@ -280,34 +280,34 @@ function getDocRev(docId, callback) {
)
}
// Helper method to support optimistic locking. Call the provided method for
// an existing doc and return the result if the rev in mongo is unchanged when
// checked afterwards. If the rev has changed, return a DocModifiedError.
function withRevCheck(doc, method, callback) {
method(doc._id, function (err, result) {
/**
* Helper method to support optimistic locking.
*
* Check that the rev of an existing doc is unchanged. If the rev has
* changed, return a DocModifiedError.
*/
function checkRevUnchanged(doc, callback) {
getDocRev(doc._id, function (err, currentRev) {
if (err) return callback(err)
getDocRev(doc._id, function (err, currentRev) {
if (err) return callback(err)
if (isNaN(currentRev) || isNaN(doc.rev)) {
return callback(
new Errors.DocRevValueError('doc rev is NaN', {
doc_id: doc._id,
rev: doc.rev,
currentRev,
})
)
}
if (doc.rev !== currentRev) {
return callback(
new Errors.DocModifiedError('doc rev has changed', {
doc_id: doc._id,
rev: doc.rev,
currentRev,
})
)
}
callback(null, result)
})
if (isNaN(currentRev) || isNaN(doc.rev)) {
return callback(
new Errors.DocRevValueError('doc rev is NaN', {
doc_id: doc._id,
rev: doc.rev,
currentRev,
})
)
}
if (doc.rev !== currentRev) {
return callback(
new Errors.DocModifiedError('doc rev has changed', {
doc_id: doc._id,
rev: doc.rev,
currentRev,
})
)
}
callback()
})
}
@@ -342,7 +342,7 @@ module.exports = {
markDocAsArchived,
getDocVersion,
setDocVersion,
withRevCheck,
checkRevUnchanged,
destroyProject,
}