Initialise full project history for old projects when project opened (#4687)

* Initialise full project history for old projects when project opened

This begins a second attempt at initialising the full project history in
the background for projects without a full project history id.

The original web-internal#4345 was reverted in web-internal#4353. This
commit reverts the revert, and adds an additional flush of the project
before initialising full project history.

GitOrigin-RevId: ac263dca8cf0d80186fee916a76e5572ec5649d4
This commit is contained in:
Thomas
2021-08-13 12:58:56 +00:00
committed by Copybot
parent 3ace29999b
commit 7517a818b2
6 changed files with 104 additions and 30 deletions
@@ -54,6 +54,9 @@ describe('ProjectController', function () {
.stub()
.callsArgWith(2, null, { _id: this.project_id }),
}
this.ProjectHistoryHandler = {
ensureHistoryExistsForProject: sinon.stub().callsArg(1),
}
this.SubscriptionLocator = { getUsersSubscription: sinon.stub() }
this.LimitationsManager = { hasPaidSubscription: sinon.stub() }
this.TagsHandler = { getAllTags: sinon.stub() }
@@ -140,6 +143,7 @@ describe('ProjectController', function () {
'./ProjectDeleter': this.ProjectDeleter,
'./ProjectDuplicator': this.ProjectDuplicator,
'./ProjectCreationHandler': this.ProjectCreationHandler,
'./ProjectHistoryHandler': this.ProjectHistoryHandler,
'../Editor/EditorController': this.EditorController,
'../User/UserController': this.UserController,
'./ProjectHelper': this.ProjectHelper,
@@ -1024,6 +1028,18 @@ describe('ProjectController', function () {
this.ProjectController.loadEditor(this.req, this.res)
})
it('should ensureHistoryExistsForProject if saas and project_history enabled', function (done) {
this.Features.hasFeature.withArgs('saas').returns(true)
this.settings.apis.project_history = 'enabled'
this.res.render = (pageName, opts) => {
this.ProjectHistoryHandler.ensureHistoryExistsForProject
.calledWith(this.project_id)
.should.equal(true)
done()
}
this.ProjectController.loadEditor(this.req, this.res)
})
it('should mark project as opened', function (done) {
this.res.render = (pageName, opts) => {
this.ProjectUpdateHandler.markAsOpened
@@ -51,6 +51,7 @@ describe('ProjectHistoryHandler', function () {
'./ProjectDetailsHandler': (this.ProjectDetailsHandler = {}),
'../History/HistoryManager': (this.HistoryManager = {}),
'./ProjectEntityUpdateHandler': (this.ProjectEntityUpdateHandler = {}),
'../DocumentUpdater/DocumentUpdaterHandler': (this.DocumentUpdaterHandler = {}),
},
}))
})
@@ -62,9 +63,10 @@ describe('ProjectHistoryHandler', function () {
.stub()
.callsArgWith(0, null, { overleaf_id: this.newHistoryId })
this.HistoryManager.flushProject = sinon.stub().callsArg(1)
return (this.ProjectEntityUpdateHandler.resyncProjectHistory = sinon
this.HistoryManager.forceResyncProject = sinon.stub().callsArg(1)
this.DocumentUpdaterHandler.flushProjectToMongoAndDelete = sinon
.stub()
.callsArg(1))
.callsArg(1)
})
describe('when the history does not already exist', function () {
@@ -101,14 +103,21 @@ describe('ProjectHistoryHandler', function () {
.should.equal(true)
})
it('should resync the project history', function () {
return this.ProjectEntityUpdateHandler.resyncProjectHistory
it('should trigger a hard resync of the project history', function () {
return this.HistoryManager.forceResyncProject
.calledWith(project_id)
.should.equal(true)
})
it('should flush the project history', function () {
it('should flush the project history (twice)', function () {
this.HistoryManager.flushProject.calledTwice.should.equal(true)
return this.HistoryManager.flushProject
.alwaysCalledWith(project_id)
.should.equal(true)
})
it('should tell docupdater to flush and delete', function () {
return this.DocumentUpdaterHandler.flushProjectToMongoAndDelete
.calledWith(project_id)
.should.equal(true)
})
@@ -146,10 +155,8 @@ describe('ProjectHistoryHandler', function () {
return this.ProjectModel.updateOne.called.should.equal(false)
})
it('should not resync the project history', function () {
return this.ProjectEntityUpdateHandler.resyncProjectHistory.called.should.equal(
false
)
it('should not trigger a hard resync of the project history', function () {
return this.HistoryManager.forceResyncProject.called.should.equal(false)
})
it('should not flush the project history', function () {