1
0
Fork 0
mirror of https://github.com/overleaf/overleaf.git synced 2025-03-14 14:13:26 +00:00

Merge pull request from overleaf/em-flush-docupdater-on-rename

Flush project in docupdater after a rename

GitOrigin-RevId: f08e722e9eb65e281965fe2603f8e97024edb8e9
This commit is contained in:
Eric Mc Sween 2023-01-09 07:54:36 -05:00 committed by Copybot
parent 3cbd460259
commit bde79780a7
2 changed files with 100 additions and 84 deletions
services/web
app/src/Features/Project
test/unit/src/Project

View file

@ -1246,6 +1246,10 @@ const ProjectEntityUpdateHandler = {
return callback(new Error('No entityType set'))
}
entityType = entityType.toLowerCase()
DocumentUpdaterHandler.flushProjectToMongo(projectId, err => {
if (err) {
return callback(err)
}
ProjectEntityMongoUpdateHandler.moveEntity(
projectId,
entityId,
@ -1259,9 +1263,8 @@ const ProjectEntityUpdateHandler = {
project.overleaf &&
project.overleaf.history &&
project.overleaf.history.id
// do not wait
TpdsUpdateSender.promises
.moveEntity({
TpdsUpdateSender.moveEntity(
{
projectId,
projectName: project.name,
startPath,
@ -1270,10 +1273,11 @@ const ProjectEntityUpdateHandler = {
entityId,
entityType,
folderId: destFolderId,
})
.catch(err => {
},
err => {
if (err) {
logger.error({ err }, 'error sending tpds update')
})
}
DocumentUpdaterHandler.updateProjectStructure(
projectId,
projectHistoryId,
@ -1284,6 +1288,9 @@ const ProjectEntityUpdateHandler = {
)
}
)
}
)
})
}),
renameEntity: wrapWithLock(function (
@ -1305,6 +1312,10 @@ const ProjectEntityUpdateHandler = {
}
entityType = entityType.toLowerCase()
DocumentUpdaterHandler.flushProjectToMongo(projectId, err => {
if (err) {
return callback(err)
}
ProjectEntityMongoUpdateHandler.renameEntity(
projectId,
entityId,
@ -1318,9 +1329,8 @@ const ProjectEntityUpdateHandler = {
project.overleaf &&
project.overleaf.history &&
project.overleaf.history.id
// do not wait
TpdsUpdateSender.promises
.moveEntity({
TpdsUpdateSender.moveEntity(
{
projectId,
projectName: project.name,
startPath,
@ -1329,10 +1339,11 @@ const ProjectEntityUpdateHandler = {
entityId,
entityType,
folderId: null, // this means the folder has not changed
})
.catch(err => {
},
err => {
if (err) {
logger.error({ err }, 'error sending tpds update')
})
}
DocumentUpdaterHandler.updateProjectStructure(
projectId,
projectHistoryId,
@ -1343,6 +1354,9 @@ const ProjectEntityUpdateHandler = {
)
}
)
}
)
})
}),
// This doesn't directly update project structure but we need to take the lock

View file

@ -76,6 +76,7 @@ describe('ProjectEntityUpdateHandler', function () {
}
this.DocumentUpdaterHandler = {
flushDocToMongo: sinon.stub().yields(),
flushProjectToMongo: sinon.stub().yields(),
updateProjectStructure: sinon.stub().yields(),
setDocument: sinon.stub(),
resyncProjectHistory: sinon.stub().yields(),
@ -128,10 +129,7 @@ describe('ProjectEntityUpdateHandler', function () {
addFile: sinon.stub().yields(),
addDoc: sinon.stub(),
deleteEntity: sinon.stub().yields(),
moveEntity: sinon.stub(),
promises: {
moveEntity: sinon.stub().resolves(),
},
moveEntity: sinon.stub().yields(),
}
this.FileStoreHandler = {
copyFile: sinon.stub(),
@ -1786,7 +1784,7 @@ describe('ProjectEntityUpdateHandler', function () {
})
it('notifies tpds', function () {
this.TpdsUpdateSender.promises.moveEntity
this.TpdsUpdateSender.moveEntity
.calledWith({
projectId,
projectName: this.project_name,
@ -1807,8 +1805,7 @@ describe('ProjectEntityUpdateHandler', function () {
projectHistoryId,
userId,
this.changes,
this.source,
this.callback
this.source
)
.should.equal(true)
})
@ -1850,7 +1847,7 @@ describe('ProjectEntityUpdateHandler', function () {
})
it('notifies tpds', function () {
this.TpdsUpdateSender.promises.moveEntity
this.TpdsUpdateSender.moveEntity
.calledWith({
projectId,
projectName: this.project_name,
@ -1864,6 +1861,12 @@ describe('ProjectEntityUpdateHandler', function () {
.should.equal(true)
})
it('flushes the project in doc updater', function () {
this.DocumentUpdaterHandler.flushProjectToMongo.should.have.been.calledWith(
projectId
)
})
it('sends the changes in project structure to the doc updater', function () {
this.DocumentUpdaterHandler.updateProjectStructure
.calledWith(
@ -1871,8 +1874,7 @@ describe('ProjectEntityUpdateHandler', function () {
projectHistoryId,
userId,
this.changes,
this.source,
this.callback
this.source
)
.should.equal(true)
})