From a220794d32d93e269737fccbc924b6ec3a1b6cc8 Mon Sep 17 00:00:00 2001 From: Hayden Faulds Date: Fri, 13 Apr 2018 14:13:18 +0100 Subject: [PATCH] add projectHistoryId to resync updates --- .../document-updater/app/coffee/DocumentManager.coffee | 8 ++++---- .../document-updater/app/coffee/HistoryManager.coffee | 4 ++-- .../document-updater/app/coffee/HttpController.coffee | 4 ++-- .../app/coffee/ProjectHistoryRedisManager.coffee | 6 ++++-- .../coffee/DocumentManager/DocumentManagerTests.coffee | 8 ++++---- .../coffee/HistoryManager/HistoryManagerTests.coffee | 5 +++-- .../coffee/HttpController/HttpControllerTests.coffee | 9 +++++---- 7 files changed, 24 insertions(+), 20 deletions(-) diff --git a/services/document-updater/app/coffee/DocumentManager.coffee b/services/document-updater/app/coffee/DocumentManager.coffee index 8b4f4192ec..43c02bfc26 100644 --- a/services/document-updater/app/coffee/DocumentManager.coffee +++ b/services/document-updater/app/coffee/DocumentManager.coffee @@ -181,15 +181,15 @@ module.exports = DocumentManager = callback(null, lines, version) resyncDocContents: (project_id, doc_id, callback) -> - RedisManager.getDoc project_id, doc_id, (error, lines, version, ranges, pathname) -> + RedisManager.getDoc project_id, doc_id, (error, lines, version, ranges, pathname, projectHistoryId) -> return callback(error) if error? if !lines? or !version? - PersistenceManager.getDoc project_id, doc_id, (error, lines, version, ranges, pathname) -> + PersistenceManager.getDoc project_id, doc_id, (error, lines, version, ranges, pathname, projectHistoryId) -> return callback(error) if error? - ProjectHistoryRedisManager.queueResyncDocContent project_id, doc_id, lines, version, pathname, callback + ProjectHistoryRedisManager.queueResyncDocContent project_id, projectHistoryId, doc_id, lines, version, pathname, callback else - ProjectHistoryRedisManager.queueResyncDocContent project_id, doc_id, lines, version, pathname, callback + ProjectHistoryRedisManager.queueResyncDocContent project_id, projectHistoryId, doc_id, lines, version, pathname, callback getDocWithLock: (project_id, doc_id, callback = (error, lines, version) ->) -> UpdateManager = require "./UpdateManager" diff --git a/services/document-updater/app/coffee/HistoryManager.coffee b/services/document-updater/app/coffee/HistoryManager.coffee index c1371615f7..9d39166681 100644 --- a/services/document-updater/app/coffee/HistoryManager.coffee +++ b/services/document-updater/app/coffee/HistoryManager.coffee @@ -65,8 +65,8 @@ module.exports = HistoryManager = newBlock = Math.floor(length / threshold) return newBlock != prevBlock - resyncProjectHistory: (project_id, docs, files, callback) -> - ProjectHistoryRedisManager.queueResyncProjectStructure project_id, docs, files, (error) -> + resyncProjectHistory: (project_id, projectHistoryId, docs, files, callback) -> + ProjectHistoryRedisManager.queueResyncProjectStructure project_id, projectHistoryId, docs, files, (error) -> return callback(error) if error? DocumentManager = require "./DocumentManager" resyncDoc = (doc, cb) -> diff --git a/services/document-updater/app/coffee/HttpController.coffee b/services/document-updater/app/coffee/HttpController.coffee index ce4d8bf637..63421db755 100644 --- a/services/document-updater/app/coffee/HttpController.coffee +++ b/services/document-updater/app/coffee/HttpController.coffee @@ -172,10 +172,10 @@ module.exports = HttpController = resyncProjectHistory: (req, res, next = (error) ->) -> project_id = req.params.project_id - {docs, files} = req.body + {projectHistoryId, docs, files} = req.body logger.log {project_id, docs, files}, "queuing project history resync via http" - HistoryManager.resyncProjectHistory project_id, docs, files, (error) -> + HistoryManager.resyncProjectHistory project_id, projectHistoryId, docs, files, (error) -> return next(error) if error? logger.log {project_id}, "queued project history resync via http" res.send 204 diff --git a/services/document-updater/app/coffee/ProjectHistoryRedisManager.coffee b/services/document-updater/app/coffee/ProjectHistoryRedisManager.coffee index c92b7277f4..625ca7fde9 100644 --- a/services/document-updater/app/coffee/ProjectHistoryRedisManager.coffee +++ b/services/document-updater/app/coffee/ProjectHistoryRedisManager.coffee @@ -38,21 +38,23 @@ module.exports = ProjectHistoryRedisManager = ProjectHistoryRedisManager.queueOps project_id, jsonUpdate, callback - queueResyncProjectStructure: (project_id, docs, files, callback) -> + queueResyncProjectStructure: (project_id, projectHistoryId, docs, files, callback) -> logger.log {project_id, docs, files}, "queue project structure resync" projectUpdate = resyncProjectStructure: { docs, files } + projectHistoryId: projectHistoryId meta: ts: new Date() jsonUpdate = JSON.stringify projectUpdate ProjectHistoryRedisManager.queueOps project_id, jsonUpdate, callback - queueResyncDocContent: (project_id, doc_id, lines, version, pathname, callback) -> + queueResyncDocContent: (project_id, projectHistoryId, doc_id, lines, version, pathname, callback) -> logger.log {project_id, doc_id, lines, version, pathname}, "queue doc content resync" projectUpdate = resyncDocContent: content: lines.join("\n"), version: version + projectHistoryId: projectHistoryId path: pathname doc: doc_id meta: diff --git a/services/document-updater/test/unit/coffee/DocumentManager/DocumentManagerTests.coffee b/services/document-updater/test/unit/coffee/DocumentManager/DocumentManagerTests.coffee index a2d55d1cb3..d4262278d6 100644 --- a/services/document-updater/test/unit/coffee/DocumentManager/DocumentManagerTests.coffee +++ b/services/document-updater/test/unit/coffee/DocumentManager/DocumentManagerTests.coffee @@ -472,7 +472,7 @@ describe "DocumentManager", -> describe "resyncDocContents", -> describe "when doc is loaded in redis", -> beforeEach -> - @RedisManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname) + @RedisManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname, @projectHistoryId) @ProjectHistoryRedisManager.queueResyncDocContent = sinon.stub() @DocumentManager.resyncDocContents @project_id, @doc_id, @callback @@ -483,13 +483,13 @@ describe "DocumentManager", -> it "queues a resync doc content update", -> @ProjectHistoryRedisManager.queueResyncDocContent - .calledWith(@project_id, @doc_id, @lines, @version, @pathname, @callback) + .calledWith(@project_id, @projectHistoryId, @doc_id, @lines, @version, @pathname, @callback) .should.equal true describe "when doc is not loaded in redis", -> beforeEach -> @RedisManager.getDoc = sinon.stub().callsArgWith(2, null) - @PersistenceManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname) + @PersistenceManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname, @projectHistoryId) @ProjectHistoryRedisManager.queueResyncDocContent = sinon.stub() @DocumentManager.resyncDocContents @project_id, @doc_id, @callback @@ -505,5 +505,5 @@ describe "DocumentManager", -> it "queues a resync doc content update", -> @ProjectHistoryRedisManager.queueResyncDocContent - .calledWith(@project_id, @doc_id, @lines, @version, @pathname, @callback) + .calledWith(@project_id, @projectHistoryId, @doc_id, @lines, @version, @pathname, @callback) .should.equal true diff --git a/services/document-updater/test/unit/coffee/HistoryManager/HistoryManagerTests.coffee b/services/document-updater/test/unit/coffee/HistoryManager/HistoryManagerTests.coffee index e207cde99d..2233610d28 100644 --- a/services/document-updater/test/unit/coffee/HistoryManager/HistoryManagerTests.coffee +++ b/services/document-updater/test/unit/coffee/HistoryManager/HistoryManagerTests.coffee @@ -164,6 +164,7 @@ describe "HistoryManager", -> describe "resyncProjectHistory", -> beforeEach -> + @projectHistoryId = 'history-id-1234' @docs = [ doc: @doc_id path: 'main.tex' @@ -175,11 +176,11 @@ describe "HistoryManager", -> ] @ProjectHistoryRedisManager.queueResyncProjectStructure = sinon.stub().yields() @DocumentManager.resyncDocContentsWithLock = sinon.stub().yields() - @HistoryManager.resyncProjectHistory @project_id, @docs, @files, @callback + @HistoryManager.resyncProjectHistory @project_id, @projectHistoryId, @docs, @files, @callback it "should queue a project structure reync", -> @ProjectHistoryRedisManager.queueResyncProjectStructure - .calledWith(@project_id, @docs, @files) + .calledWith(@project_id, @projectHistoryId, @docs, @files) .should.equal true it "should queue doc content reyncs", -> diff --git a/services/document-updater/test/unit/coffee/HttpController/HttpControllerTests.coffee b/services/document-updater/test/unit/coffee/HttpController/HttpControllerTests.coffee index fca1614c2d..e36f54ee3d 100644 --- a/services/document-updater/test/unit/coffee/HttpController/HttpControllerTests.coffee +++ b/services/document-updater/test/unit/coffee/HttpController/HttpControllerTests.coffee @@ -548,23 +548,24 @@ describe "HttpController", -> describe "resyncProjectHistory", -> beforeEach -> + @projectHistoryId = "history-id-123" @docs = sinon.stub() @files = sinon.stub() @fileUpdates = sinon.stub() @req = body: - {@docs, @files} + {@projectHistoryId, @docs, @files} params: project_id: @project_id describe "successfully", -> beforeEach -> - @HistoryManager.resyncProjectHistory = sinon.stub().callsArg(3) + @HistoryManager.resyncProjectHistory = sinon.stub().callsArgWith(4) @HttpController.resyncProjectHistory(@req, @res, @next) it "should accept the change", -> @HistoryManager.resyncProjectHistory - .calledWith(@project_id, @docs, @files) + .calledWith(@project_id, @projectHistoryId, @docs, @files) .should.equal true it "should return a successful No Content response", -> @@ -574,7 +575,7 @@ describe "HttpController", -> describe "when an errors occurs", -> beforeEach -> - @HistoryManager.resyncProjectHistory = sinon.stub().callsArgWith(3, new Error("oops")) + @HistoryManager.resyncProjectHistory = sinon.stub().callsArgWith(4, new Error("oops")) @HttpController.resyncProjectHistory(@req, @res, @next) it "should call next with the error", ->