mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 08:03:42 -05:00
Merge pull request #7767 from overleaf/em-relax-unarchive-docs
Allow concurrent doc unarchive operations GitOrigin-RevId: 7edd1bd764125a0dc8e4a5fec643558a56e20f30
This commit is contained in:
parent
e1b07cd40a
commit
f282b5cb17
3 changed files with 9 additions and 12 deletions
|
@ -249,12 +249,13 @@ function archiveDoc(req, res, next) {
|
||||||
function unArchiveAllDocs(req, res, next) {
|
function unArchiveAllDocs(req, res, next) {
|
||||||
const { project_id: projectId } = req.params
|
const { project_id: projectId } = req.params
|
||||||
logger.log({ projectId }, 'unarchiving all docs')
|
logger.log({ projectId }, 'unarchiving all docs')
|
||||||
DocArchive.unArchiveAllDocs(projectId, function (error) {
|
DocArchive.unArchiveAllDocs(projectId, function (err) {
|
||||||
if (error) {
|
if (err) {
|
||||||
if (error instanceof Errors.DocRevValueError) {
|
if (err instanceof Errors.DocRevValueError) {
|
||||||
|
logger.warn({ err }, 'Failed to unarchive doc')
|
||||||
return res.sendStatus(409)
|
return res.sendStatus(409)
|
||||||
}
|
}
|
||||||
return next(error)
|
return next(err)
|
||||||
}
|
}
|
||||||
res.sendStatus(200)
|
res.sendStatus(200)
|
||||||
})
|
})
|
||||||
|
|
|
@ -126,14 +126,12 @@ function markDocAsArchived(docId, rev, callback) {
|
||||||
/**
|
/**
|
||||||
* Restore an archived doc
|
* Restore an archived doc
|
||||||
*
|
*
|
||||||
* This checks that inS3 is true and that the archived doc's rev matches. The
|
* This checks that the archived doc's rev matches.
|
||||||
* rev was not always stored with docs, so this check is optional.
|
|
||||||
*/
|
*/
|
||||||
function restoreArchivedDoc(projectId, docId, archivedDoc, callback) {
|
function restoreArchivedDoc(projectId, docId, archivedDoc, callback) {
|
||||||
const query = {
|
const query = {
|
||||||
_id: ObjectId(docId),
|
_id: ObjectId(docId),
|
||||||
project_id: ObjectId(projectId),
|
project_id: ObjectId(projectId),
|
||||||
inS3: true,
|
|
||||||
rev: archivedDoc.rev,
|
rev: archivedDoc.rev,
|
||||||
}
|
}
|
||||||
const update = {
|
const update = {
|
||||||
|
@ -153,7 +151,7 @@ function restoreArchivedDoc(projectId, docId, archivedDoc, callback) {
|
||||||
})
|
})
|
||||||
return callback(err)
|
return callback(err)
|
||||||
}
|
}
|
||||||
if (result.modifiedCount === 0) {
|
if (result.matchedCount === 0) {
|
||||||
return callback(
|
return callback(
|
||||||
new Errors.DocRevValueError('failed to unarchive doc', {
|
new Errors.DocRevValueError('failed to unarchive doc', {
|
||||||
docId,
|
docId,
|
||||||
|
|
|
@ -12,7 +12,7 @@ describe('MongoManager', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
this.db = {
|
this.db = {
|
||||||
docs: {
|
docs: {
|
||||||
updateOne: sinon.stub().yields(null, { modifedCount: 1 }),
|
updateOne: sinon.stub().yields(null, { matchedCount: 1 }),
|
||||||
},
|
},
|
||||||
docOps: {},
|
docOps: {},
|
||||||
}
|
}
|
||||||
|
@ -426,7 +426,6 @@ describe('MongoManager', function () {
|
||||||
{
|
{
|
||||||
_id: ObjectId(this.docId),
|
_id: ObjectId(this.docId),
|
||||||
project_id: ObjectId(this.projectId),
|
project_id: ObjectId(this.projectId),
|
||||||
inS3: true,
|
|
||||||
rev: this.archivedDoc.rev,
|
rev: this.archivedDoc.rev,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -458,7 +457,6 @@ describe('MongoManager', function () {
|
||||||
{
|
{
|
||||||
_id: ObjectId(this.docId),
|
_id: ObjectId(this.docId),
|
||||||
project_id: ObjectId(this.projectId),
|
project_id: ObjectId(this.projectId),
|
||||||
inS3: true,
|
|
||||||
rev: this.archivedDoc.rev,
|
rev: this.archivedDoc.rev,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -476,7 +474,7 @@ describe('MongoManager', function () {
|
||||||
|
|
||||||
describe("when the update doesn't succeed", function () {
|
describe("when the update doesn't succeed", function () {
|
||||||
it('throws a DocRevValueError', function (done) {
|
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.MongoManager.restoreArchivedDoc(
|
||||||
this.projectId,
|
this.projectId,
|
||||||
this.docId,
|
this.docId,
|
||||||
|
|
Loading…
Reference in a new issue