diff --git a/services/web/app/coffee/Features/Project/ProjectEntityMongoUpdateHandler.coffee b/services/web/app/coffee/Features/Project/ProjectEntityMongoUpdateHandler.coffee index 80d4795d22..a13eb370b1 100644 --- a/services/web/app/coffee/Features/Project/ProjectEntityMongoUpdateHandler.coffee +++ b/services/web/app/coffee/Features/Project/ProjectEntityMongoUpdateHandler.coffee @@ -63,7 +63,7 @@ module.exports = ProjectEntityMongoUpdateHandler = self = set["#{path.mongo}._id"] = newFileRef._id set["#{path.mongo}.created"] = new Date() set["#{path.mongo}.linkedFileData"] = newFileRef.linkedFileData - set["#{path.mongo}.rev"] = 1 + inc["#{path.mongo}.rev"] = 1 update = "$inc": inc "$set": set diff --git a/services/web/app/coffee/Features/Project/ProjectEntityUpdateHandler.coffee b/services/web/app/coffee/Features/Project/ProjectEntityUpdateHandler.coffee index 1d49b47934..8e269fe610 100644 --- a/services/web/app/coffee/Features/Project/ProjectEntityUpdateHandler.coffee +++ b/services/web/app/coffee/Features/Project/ProjectEntityUpdateHandler.coffee @@ -233,7 +233,13 @@ module.exports = ProjectEntityUpdateHandler = self = url: fileStoreUrl ] projectHistoryId = project.overleaf?.history?.id - TpdsUpdateSender.addFile {project_id:project._id, file_id:newFileRef._id, path:path.fileSystem, rev:newFileRef.rev+1, project_name:project.name}, (err) -> + # Increment the rev for an in-place update (with the same path) so the third-party-datastore + # knows this is a new file. + # Ideally we would get this from ProjectEntityMongoUpdateHandler.replaceFileWithNew + # but it returns the original oldFileRef (after incrementing the rev value in mongo), + # so we add 1 to the rev from that. This isn't atomic and relies on the lock + # but it is acceptable for now. + TpdsUpdateSender.addFile {project_id:project._id, file_id:newFileRef._id, path:path.fileSystem, rev:oldFileRef.rev + 1, project_name:project.name}, (err) -> return callback(err) if err? DocumentUpdaterHandler.updateProjectStructure project_id, projectHistoryId, userId, {oldFiles, newFiles}, callback diff --git a/services/web/test/unit/coffee/Project/ProjectEntityMongoUpdateHandlerTests.coffee b/services/web/test/unit/coffee/Project/ProjectEntityMongoUpdateHandlerTests.coffee index 7dadc7dbb2..661bef2da0 100644 --- a/services/web/test/unit/coffee/Project/ProjectEntityMongoUpdateHandlerTests.coffee +++ b/services/web/test/unit/coffee/Project/ProjectEntityMongoUpdateHandlerTests.coffee @@ -135,8 +135,8 @@ describe 'ProjectEntityMongoUpdateHandler', -> .calledWith( { _id: project_id }, { - '$inc': { 'version': 1 } - '$set': { 'file.png._id': @newFile._id, 'file.png.created': new Date(), 'file.png.linkedFileData': @linkedFileData, 'file.png.rev': 1 } + '$inc': { 'version': 1, 'file.png.rev': 1 } + '$set': { 'file.png._id': @newFile._id, 'file.png.created': new Date(), 'file.png.linkedFileData': @linkedFileData } } {} ) diff --git a/services/web/test/unit/coffee/Project/ProjectEntityUpdateHandlerTests.coffee b/services/web/test/unit/coffee/Project/ProjectEntityUpdateHandlerTests.coffee index 46403328a7..46ac50ab63 100644 --- a/services/web/test/unit/coffee/Project/ProjectEntityUpdateHandlerTests.coffee +++ b/services/web/test/unit/coffee/Project/ProjectEntityUpdateHandlerTests.coffee @@ -391,7 +391,7 @@ describe 'ProjectEntityUpdateHandler', -> @FileStoreHandler.uploadFileFromDisk = sinon.stub().yields(null, @newFileUrl) @newFile = _id: new_file_id, name: "dummy-upload-filename", rev: 0, linkedFileData: @linkedFileData - @oldFile = _id: file_id + @oldFile = _id: file_id, rev: 3 @path = "/path/to/file" @ProjectEntityMongoUpdateHandler._insertDeletedFileReference = sinon.stub().yields() @ProjectEntityMongoUpdateHandler.replaceFileWithNew = sinon.stub().yields(null, @oldFile, @project, fileSystem: @path) @@ -413,7 +413,7 @@ describe 'ProjectEntityUpdateHandler', -> project_id: project_id project_name: @project.name file_id: new_file_id - rev: @newFile.rev + 1 + rev: @oldFile.rev + 1 path: @path }) .should.equal true