Merge pull request #7767 from overleaf/em-relax-unarchive-docs

Allow concurrent doc unarchive operations

GitOrigin-RevId: 7edd1bd764125a0dc8e4a5fec643558a56e20f30
This commit is contained in:
Eric Mc Sween 2022-04-26 11:10:15 -04:00 committed by Copybot
parent e1b07cd40a
commit f282b5cb17
3 changed files with 9 additions and 12 deletions

View file

@ -249,12 +249,13 @@ function archiveDoc(req, res, next) {
function unArchiveAllDocs(req, res, next) {
const { project_id: projectId } = req.params
logger.log({ projectId }, 'unarchiving all docs')
DocArchive.unArchiveAllDocs(projectId, function (error) {
if (error) {
if (error instanceof Errors.DocRevValueError) {
DocArchive.unArchiveAllDocs(projectId, function (err) {
if (err) {
if (err instanceof Errors.DocRevValueError) {
logger.warn({ err }, 'Failed to unarchive doc')
return res.sendStatus(409)
}
return next(error)
return next(err)
}
res.sendStatus(200)
})

View file

@ -126,14 +126,12 @@ function markDocAsArchived(docId, rev, callback) {
/**
* Restore an archived doc
*
* This checks that inS3 is true and that the archived doc's rev matches. The
* rev was not always stored with docs, so this check is optional.
* This checks that the archived doc's rev matches.
*/
function restoreArchivedDoc(projectId, docId, archivedDoc, callback) {
const query = {
_id: ObjectId(docId),
project_id: ObjectId(projectId),
inS3: true,
rev: archivedDoc.rev,
}
const update = {
@ -153,7 +151,7 @@ function restoreArchivedDoc(projectId, docId, archivedDoc, callback) {
})
return callback(err)
}
if (result.modifiedCount === 0) {
if (result.matchedCount === 0) {
return callback(
new Errors.DocRevValueError('failed to unarchive doc', {
docId,

View file

@ -12,7 +12,7 @@ describe('MongoManager', function () {
beforeEach(function () {
this.db = {
docs: {
updateOne: sinon.stub().yields(null, { modifedCount: 1 }),
updateOne: sinon.stub().yields(null, { matchedCount: 1 }),
},
docOps: {},
}
@ -426,7 +426,6 @@ describe('MongoManager', function () {
{
_id: ObjectId(this.docId),
project_id: ObjectId(this.projectId),
inS3: true,
rev: this.archivedDoc.rev,
},
{
@ -458,7 +457,6 @@ describe('MongoManager', function () {
{
_id: ObjectId(this.docId),
project_id: ObjectId(this.projectId),
inS3: true,
rev: this.archivedDoc.rev,
},
{
@ -476,7 +474,7 @@ describe('MongoManager', function () {
describe("when the update doesn't succeed", function () {
it('throws a DocRevValueError', function (done) {
this.db.docs.updateOne.yields(null, { modifiedCount: 0 })
this.db.docs.updateOne.yields(null, { matchedCount: 0 })
this.MongoManager.restoreArchivedDoc(
this.projectId,
this.docId,