mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-08 19:50:47 +00:00
update DocumentManager.getDoc signature
keep alreadyLoaded flag at the end for consistency
This commit is contained in:
parent
2bbbf3c005
commit
8d3f82360c
2 changed files with 14 additions and 13 deletions
|
@ -11,7 +11,7 @@ RangesManager = require "./RangesManager"
|
|||
MAX_UNFLUSHED_AGE = 300 * 1000 # 5 mins, document should be flushed to mongo this time after a change
|
||||
|
||||
module.exports = DocumentManager =
|
||||
getDoc: (project_id, doc_id, _callback = (error, lines, version, ranges, alreadyLoaded, unflushedTime) ->) ->
|
||||
getDoc: (project_id, doc_id, _callback = (error, lines, version, ranges, unflushedTime, alreadyLoaded) ->) ->
|
||||
timer = new Metrics.Timer("docManager.getDoc")
|
||||
callback = (args...) ->
|
||||
timer.done()
|
||||
|
@ -26,9 +26,9 @@ module.exports = DocumentManager =
|
|||
logger.log {project_id, doc_id, lines, version}, "got doc from persistence API"
|
||||
RedisManager.putDocInMemory project_id, doc_id, lines, version, ranges, (error) ->
|
||||
return callback(error) if error?
|
||||
callback null, lines, version, ranges, false, null
|
||||
callback null, lines, version, ranges, null, false
|
||||
else
|
||||
callback null, lines, version, ranges, true, unflushedTime
|
||||
callback null, lines, version, ranges, unflushedTime, true
|
||||
|
||||
getDocAndRecentOps: (project_id, doc_id, fromVersion, _callback = (error, lines, version, recentOps, ranges) ->) ->
|
||||
timer = new Metrics.Timer("docManager.getDocAndRecentOps")
|
||||
|
@ -55,7 +55,7 @@ module.exports = DocumentManager =
|
|||
return callback(new Error("No lines were provided to setDoc"))
|
||||
|
||||
UpdateManager = require "./UpdateManager"
|
||||
DocumentManager.getDoc project_id, doc_id, (error, oldLines, version, ranges, alreadyLoaded) ->
|
||||
DocumentManager.getDoc project_id, doc_id, (error, oldLines, version, ranges, unflushedTime, alreadyLoaded) ->
|
||||
return callback(error) if error?
|
||||
|
||||
if oldLines? and oldLines.length > 0 and oldLines[0].text?
|
||||
|
@ -159,7 +159,7 @@ module.exports = DocumentManager =
|
|||
callback()
|
||||
|
||||
getDocAndFlushIfOld: (project_id, doc_id, callback = (error, doc) ->) ->
|
||||
DocumentManager.getDoc project_id, doc_id, (error, lines, version, ranges, alreadyLoaded, unflushedTime) ->
|
||||
DocumentManager.getDoc project_id, doc_id, (error, lines, version, ranges, unflushedTime, alreadyLoaded) ->
|
||||
return callback(error) if error?
|
||||
# if doc was already loaded see if it needs to be flushed
|
||||
if alreadyLoaded and unflushedTime? and (Date.now() - unflushedTime) > MAX_UNFLUSHED_AGE
|
||||
|
|
|
@ -27,6 +27,7 @@ describe "DocumentManager", ->
|
|||
@lines = ["one", "two", "three"]
|
||||
@version = 42
|
||||
@ranges = { comments: "mock", entries: "mock" }
|
||||
@unflushedTime = Date.now()
|
||||
|
||||
describe "flushAndDeleteDoc", ->
|
||||
describe "successfully", ->
|
||||
|
@ -149,7 +150,7 @@ describe "DocumentManager", ->
|
|||
describe "getDoc", ->
|
||||
describe "when the doc exists in Redis", ->
|
||||
beforeEach ->
|
||||
@RedisManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges)
|
||||
@RedisManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @unflushedTime)
|
||||
@DocumentManager.getDoc @project_id, @doc_id, @callback
|
||||
|
||||
it "should get the doc from Redis", ->
|
||||
|
@ -158,7 +159,7 @@ describe "DocumentManager", ->
|
|||
.should.equal true
|
||||
|
||||
it "should call the callback with the doc info", ->
|
||||
@callback.calledWith(null, @lines, @version, @ranges, true).should.equal true
|
||||
@callback.calledWith(null, @lines, @version, @ranges, @unflushedTime, true).should.equal true
|
||||
|
||||
it "should time the execution", ->
|
||||
@Metrics.Timer::done.called.should.equal true
|
||||
|
@ -186,7 +187,7 @@ describe "DocumentManager", ->
|
|||
.should.equal true
|
||||
|
||||
it "should call the callback with the doc info", ->
|
||||
@callback.calledWith(null, @lines, @version, @ranges, false).should.equal true
|
||||
@callback.calledWith(null, @lines, @version, @ranges, null, false).should.equal true
|
||||
|
||||
it "should time the execution", ->
|
||||
@Metrics.Timer::done.called.should.equal true
|
||||
|
@ -197,7 +198,7 @@ describe "DocumentManager", ->
|
|||
@beforeLines = ["before", "lines"]
|
||||
@afterLines = ["after", "lines"]
|
||||
@ops = [{ i: "foo", p: 4 }, { d: "bar", p: 42 }]
|
||||
@DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @beforeLines, @version, @ranges, true)
|
||||
@DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @beforeLines, @version, @ranges, @unflushedTime, true)
|
||||
@DiffCodec.diffAsShareJsOp = sinon.stub().callsArgWith(2, null, @ops)
|
||||
@UpdateManager.applyUpdate = sinon.stub().callsArgWith(3, null)
|
||||
@DocumentManager.flushDocIfLoaded = sinon.stub().callsArg(2)
|
||||
|
@ -248,7 +249,7 @@ describe "DocumentManager", ->
|
|||
|
||||
describe "when not already loaded", ->
|
||||
beforeEach ->
|
||||
@DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @beforeLines, @version, false)
|
||||
@DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @beforeLines, @version, null, false)
|
||||
@DocumentManager.setDoc @project_id, @doc_id, @afterLines, @source, @user_id, false, @callback
|
||||
|
||||
it "should flush and delete the doc from the doc updater", ->
|
||||
|
@ -388,7 +389,7 @@ describe "DocumentManager", ->
|
|||
describe "when the doc is in Redis", ->
|
||||
describe "and has changes to be flushed", ->
|
||||
beforeEach ->
|
||||
@DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, true, Date.now() - 1e9)
|
||||
@DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, Date.now() - 1e9, true)
|
||||
@DocumentManager.getDocAndFlushIfOld @project_id, @doc_id, @callback
|
||||
|
||||
it "should get the doc", ->
|
||||
|
@ -406,7 +407,7 @@ describe "DocumentManager", ->
|
|||
|
||||
describe "and has only changes that don't need to be flushed", ->
|
||||
beforeEach ->
|
||||
@DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, true, Date.now() - 100)
|
||||
@DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, Date.now() - 100, true)
|
||||
@DocumentManager.getDocAndFlushIfOld @project_id, @doc_id, @callback
|
||||
|
||||
it "should get the doc", ->
|
||||
|
@ -423,7 +424,7 @@ describe "DocumentManager", ->
|
|||
|
||||
describe "when the doc is not in Redis", ->
|
||||
beforeEach ->
|
||||
@DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, false)
|
||||
@DocumentManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, null, false)
|
||||
@DocumentManager.getDocAndFlushIfOld @project_id, @doc_id, @callback
|
||||
|
||||
it "should get the doc", ->
|
||||
|
|
Loading…
Add table
Reference in a new issue