mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
add projectHistoryId to resync updates
This commit is contained in:
parent
fb1852a593
commit
a220794d32
7 changed files with 24 additions and 20 deletions
|
@ -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"
|
||||
|
|
|
@ -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) ->
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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", ->
|
||||
|
|
|
@ -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", ->
|
||||
|
|
Loading…
Reference in a new issue