From f282b5cb1752302d6860b6a5cc8f8d3e2e0431b0 Mon Sep 17 00:00:00 2001 From: Eric Mc Sween Date: Tue, 26 Apr 2022 11:10:15 -0400 Subject: [PATCH] Merge pull request #7767 from overleaf/em-relax-unarchive-docs Allow concurrent doc unarchive operations GitOrigin-RevId: 7edd1bd764125a0dc8e4a5fec643558a56e20f30 --- services/docstore/app/js/HttpController.js | 9 +++++---- services/docstore/app/js/MongoManager.js | 6 ++---- services/docstore/test/unit/js/MongoManagerTests.js | 6 ++---- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/services/docstore/app/js/HttpController.js b/services/docstore/app/js/HttpController.js index 814267196d..55f0c1226e 100644 --- a/services/docstore/app/js/HttpController.js +++ b/services/docstore/app/js/HttpController.js @@ -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) }) diff --git a/services/docstore/app/js/MongoManager.js b/services/docstore/app/js/MongoManager.js index b901c8defb..1c3b71d262 100644 --- a/services/docstore/app/js/MongoManager.js +++ b/services/docstore/app/js/MongoManager.js @@ -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, diff --git a/services/docstore/test/unit/js/MongoManagerTests.js b/services/docstore/test/unit/js/MongoManagerTests.js index 08f216f552..1fcf1abe98 100644 --- a/services/docstore/test/unit/js/MongoManagerTests.js +++ b/services/docstore/test/unit/js/MongoManagerTests.js @@ -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,