mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #3372 from overleaf/jpa-archive-docs-on-soft-delete
[ProjectDeleter] flush docs out of mongo when soft-deleting a project GitOrigin-RevId: 52f3e1298af5ca481ba9b27b18c9190063019988
This commit is contained in:
parent
94092c905b
commit
da8663fd0f
2 changed files with 39 additions and 0 deletions
|
@ -240,6 +240,18 @@ async function deleteProject(projectId, options = {}) {
|
|||
projectId
|
||||
)
|
||||
|
||||
try {
|
||||
// OPTIMIZATION: flush docs out of mongo
|
||||
await DocstoreManager.promises.archiveProject(projectId)
|
||||
} catch (err) {
|
||||
// It is OK to fail here, the docs will get hard-deleted eventually after
|
||||
// the grace-period for soft-deleted projects has passed.
|
||||
logger.warn(
|
||||
{ projectId, err },
|
||||
'failed archiving doc via docstore as part of project soft-deletion'
|
||||
)
|
||||
}
|
||||
|
||||
const memberIds = await CollaboratorsGetter.promises.getMemberIds(projectId)
|
||||
|
||||
// fire these jobs in the background
|
||||
|
|
|
@ -112,6 +112,7 @@ describe('ProjectDeleter', function() {
|
|||
|
||||
this.DocstoreManager = {
|
||||
promises: {
|
||||
archiveProject: sinon.stub().resolves(),
|
||||
destroyProject: sinon.stub().resolves()
|
||||
}
|
||||
}
|
||||
|
@ -320,6 +321,32 @@ describe('ProjectDeleter', function() {
|
|||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should flush docs out of mongo', async function() {
|
||||
this.ProjectMock.expects('deleteOne')
|
||||
.chain('exec')
|
||||
.resolves()
|
||||
this.DeletedProjectMock.expects('updateOne').resolves()
|
||||
await this.ProjectDeleter.promises.deleteProject(this.project._id, {
|
||||
deleterUser: this.user,
|
||||
ipAddress: this.ip
|
||||
})
|
||||
expect(
|
||||
this.DocstoreManager.promises.archiveProject
|
||||
).to.have.been.calledWith(this.project._id)
|
||||
})
|
||||
|
||||
it('should flush docs out of mongo and ignore errors', async function() {
|
||||
this.ProjectMock.expects('deleteOne')
|
||||
.chain('exec')
|
||||
.resolves()
|
||||
this.DeletedProjectMock.expects('updateOne').resolves()
|
||||
this.DocstoreManager.promises.archiveProject.rejects(new Error('foo'))
|
||||
await this.ProjectDeleter.promises.deleteProject(this.project._id, {
|
||||
deleterUser: this.user,
|
||||
ipAddress: this.ip
|
||||
})
|
||||
})
|
||||
|
||||
it('should removeProjectFromAllTags', async function() {
|
||||
this.ProjectMock.expects('deleteOne')
|
||||
.chain('exec')
|
||||
|
|
Loading…
Reference in a new issue