mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Proxy ranges between doc updater and docstore
This commit is contained in:
parent
a5d2183441
commit
1830d41eba
8 changed files with 36 additions and 24 deletions
|
@ -45,13 +45,13 @@ module.exports = DocstoreManager =
|
|||
return callback(error) if error?
|
||||
if 200 <= res.statusCode < 300
|
||||
logger.log doc_id: doc_id, project_id: project_id, version: doc.version, rev: doc.rev, "got doc from docstore api"
|
||||
callback(null, doc.lines, doc.rev, doc.version)
|
||||
callback(null, doc.lines, doc.rev, doc.version, doc.ranges)
|
||||
else
|
||||
error = new Error("docstore api responded with non-success code: #{res.statusCode}")
|
||||
logger.error err: error, project_id: project_id, doc_id: doc_id, "error getting doc from docstore"
|
||||
callback(error)
|
||||
|
||||
updateDoc: (project_id, doc_id, lines, version, callback = (error, modified, rev) ->) ->
|
||||
updateDoc: (project_id, doc_id, lines, version, ranges, callback = (error, modified, rev) ->) ->
|
||||
logger.log project_id: project_id, doc_id: doc_id, "updating doc in docstore api"
|
||||
url = "#{settings.apis.docstore.url}/project/#{project_id}/doc/#{doc_id}"
|
||||
request.post {
|
||||
|
@ -59,6 +59,7 @@ module.exports = DocstoreManager =
|
|||
json:
|
||||
lines: lines
|
||||
version: version
|
||||
ranges: ranges
|
||||
}, (error, res, result) ->
|
||||
return callback(error) if error?
|
||||
if 200 <= res.statusCode < 300
|
||||
|
|
|
@ -95,7 +95,7 @@ module.exports = DocumentUpdaterHandler =
|
|||
logger.error err: error, project_id: project_id, doc_id: doc_id, "document updater returned failure status code: #{res.statusCode}"
|
||||
return callback(error)
|
||||
|
||||
getDocument: (project_id, doc_id, fromVersion, callback = (error, exists, doclines, version) ->) ->
|
||||
getDocument: (project_id, doc_id, fromVersion, callback = (error, doclines, version, ranges, ops) ->) ->
|
||||
timer = new metrics.Timer("get-document")
|
||||
url = "#{settings.apis.documentupdater.url}/project/#{project_id}/doc/#{doc_id}?fromVersion=#{fromVersion}"
|
||||
logger.log project_id:project_id, doc_id: doc_id, "getting doc from document updater"
|
||||
|
@ -110,7 +110,7 @@ module.exports = DocumentUpdaterHandler =
|
|||
body = JSON.parse(body)
|
||||
catch error
|
||||
return callback(error)
|
||||
callback null, body.lines, body.version, body.ops
|
||||
callback null, body.lines, body.version, body.ranges, body.ops
|
||||
else
|
||||
logger.error project_id:project_id, doc_id:doc_id, url: url, "doc updater returned a non-success status code: #{res.statusCode}"
|
||||
callback new Error("doc updater returned a non-success status code: #{res.statusCode}")
|
||||
|
|
|
@ -7,7 +7,7 @@ module.exports =
|
|||
doc_id = req.params.doc_id
|
||||
plain = req?.query?.plain == 'true'
|
||||
logger.log doc_id:doc_id, project_id:project_id, "receiving get document request from api (docupdater)"
|
||||
ProjectEntityHandler.getDoc project_id, doc_id, (error, lines, rev, version) ->
|
||||
ProjectEntityHandler.getDoc project_id, doc_id, (error, lines, rev, version, ranges) ->
|
||||
if error?
|
||||
logger.err err:error, doc_id:doc_id, project_id:project_id, "error finding element for getDocument"
|
||||
return next(error)
|
||||
|
@ -19,14 +19,15 @@ module.exports =
|
|||
res.send JSON.stringify {
|
||||
lines: lines
|
||||
version: version
|
||||
ranges: ranges
|
||||
}
|
||||
|
||||
setDocument: (req, res, next = (error) ->) ->
|
||||
project_id = req.params.Project_id
|
||||
doc_id = req.params.doc_id
|
||||
{lines, version} = req.body
|
||||
{lines, version, ranges} = req.body
|
||||
logger.log doc_id:doc_id, project_id:project_id, "receiving set document request from api (docupdater)"
|
||||
ProjectEntityHandler.updateDocLines project_id, doc_id, lines, version, (error) ->
|
||||
ProjectEntityHandler.updateDocLines project_id, doc_id, lines, version, ranges, (error) ->
|
||||
if error?
|
||||
logger.err err:error, doc_id:doc_id, project_id:project_id, "error finding element for getDocument"
|
||||
return next(error)
|
||||
|
|
|
@ -126,7 +126,7 @@ module.exports = ProjectEntityHandler =
|
|||
doc = new Doc name: docName
|
||||
# Put doc in docstore first, so that if it errors, we don't have a doc_id in the project
|
||||
# which hasn't been created in docstore.
|
||||
DocstoreManager.updateDoc project_id.toString(), doc._id.toString(), docLines, 0, (err, modified, rev) ->
|
||||
DocstoreManager.updateDoc project_id.toString(), doc._id.toString(), docLines, 0, {}, (err, modified, rev) ->
|
||||
return callback(err) if err?
|
||||
|
||||
ProjectEntityHandler._putElement project, folder_id, doc, "doc", (err, result)=>
|
||||
|
@ -292,7 +292,7 @@ module.exports = ProjectEntityHandler =
|
|||
return callback(err)
|
||||
callback(err, folder, parentFolder_id)
|
||||
|
||||
updateDocLines : (project_id, doc_id, lines, version, callback = (error) ->)->
|
||||
updateDocLines : (project_id, doc_id, lines, version, ranges, callback = (error) ->)->
|
||||
ProjectGetter.getProjectWithoutDocLines project_id, (err, project)->
|
||||
return callback(err) if err?
|
||||
return callback(new Errors.NotFoundError("project not found")) if !project?
|
||||
|
@ -307,7 +307,7 @@ module.exports = ProjectEntityHandler =
|
|||
return callback(error)
|
||||
|
||||
logger.log project_id: project_id, doc_id: doc_id, "telling docstore manager to update doc"
|
||||
DocstoreManager.updateDoc project_id, doc_id, lines, version, (err, modified, rev) ->
|
||||
DocstoreManager.updateDoc project_id, doc_id, lines, version, ranges, (err, modified, rev) ->
|
||||
if err?
|
||||
logger.error err: err, doc_id: doc_id, project_id:project_id, lines: lines, "error sending doc to docstore"
|
||||
return callback(err)
|
||||
|
|
|
@ -57,12 +57,13 @@ describe "DocstoreManager", ->
|
|||
@lines = ["mock", "doc", "lines"]
|
||||
@rev = 5
|
||||
@version = 42
|
||||
@ranges = { "mock": "ranges" }
|
||||
@modified = true
|
||||
|
||||
describe "with a successful response code", ->
|
||||
beforeEach ->
|
||||
@request.post = sinon.stub().callsArgWith(1, null, statusCode: 204, { modified: @modified, rev: @rev })
|
||||
@DocstoreManager.updateDoc @project_id, @doc_id, @lines, @version, @callback
|
||||
@DocstoreManager.updateDoc @project_id, @doc_id, @lines, @version, @ranges, @callback
|
||||
|
||||
it "should update the doc in the docstore api", ->
|
||||
@request.post
|
||||
|
@ -71,6 +72,7 @@ describe "DocstoreManager", ->
|
|||
json:
|
||||
lines: @lines
|
||||
version: @version
|
||||
ranges: @ranges
|
||||
})
|
||||
.should.equal true
|
||||
|
||||
|
@ -80,7 +82,7 @@ describe "DocstoreManager", ->
|
|||
describe "with a failed response code", ->
|
||||
beforeEach ->
|
||||
@request.post = sinon.stub().callsArgWith(1, null, statusCode: 500, "")
|
||||
@DocstoreManager.updateDoc @project_id, @doc_id, @lines, @version, @callback
|
||||
@DocstoreManager.updateDoc @project_id, @doc_id, @lines, @version, @ranges, @callback
|
||||
|
||||
it "should call the callback with an error", ->
|
||||
@callback.calledWith(new Error("docstore api responded with non-success code: 500")).should.equal true
|
||||
|
@ -100,6 +102,7 @@ describe "DocstoreManager", ->
|
|||
lines: @lines = ["mock", "doc", "lines"]
|
||||
rev: @rev = 5
|
||||
version: @version = 42
|
||||
ranges: @ranges = { "mock": "ranges" }
|
||||
|
||||
describe "with a successful response code", ->
|
||||
beforeEach ->
|
||||
|
@ -115,7 +118,7 @@ describe "DocstoreManager", ->
|
|||
.should.equal true
|
||||
|
||||
it "should call the callback with the lines, version and rev", ->
|
||||
@callback.calledWith(null, @lines, @rev, @version).should.equal true
|
||||
@callback.calledWith(null, @lines, @rev, @version, @ranges).should.equal true
|
||||
|
||||
describe "with a failed response code", ->
|
||||
beforeEach ->
|
||||
|
@ -148,7 +151,7 @@ describe "DocstoreManager", ->
|
|||
.should.equal true
|
||||
|
||||
it "should call the callback with the lines, version and rev", ->
|
||||
@callback.calledWith(null, @lines, @rev, @version).should.equal true
|
||||
@callback.calledWith(null, @lines, @rev, @version, @ranges).should.equal true
|
||||
|
||||
describe "getAllDocs", ->
|
||||
describe "with a successful response code", ->
|
||||
|
|
|
@ -267,6 +267,7 @@ describe 'DocumentUpdaterHandler - Flushing documents :', ->
|
|||
lines: @lines
|
||||
version: @version
|
||||
ops: @ops = ["mock-op-1", "mock-op-2"]
|
||||
ranges: @ranges = {"mock":"ranges"}
|
||||
@fromVersion = 2
|
||||
@request.get = sinon.stub().callsArgWith(1, null, {statusCode: 200}, @body)
|
||||
@handler.getDocument @project_id, @doc_id, @fromVersion, @callback
|
||||
|
@ -276,7 +277,7 @@ describe 'DocumentUpdaterHandler - Flushing documents :', ->
|
|||
@request.get.calledWith(url).should.equal true
|
||||
|
||||
it "should call the callback with the lines and version", ->
|
||||
@callback.calledWith(null, @lines, @version, @ops).should.equal true
|
||||
@callback.calledWith(null, @lines, @version, @ranges, @ops).should.equal true
|
||||
|
||||
describe "when the document updater API returns an error", ->
|
||||
beforeEach ->
|
||||
|
|
|
@ -23,6 +23,7 @@ describe "DocumentController", ->
|
|||
@doc_id = "doc-id-123"
|
||||
@doc_lines = ["one", "two", "three"]
|
||||
@version = 42
|
||||
@ranges = {"mock": "ranges"}
|
||||
@rev = 5
|
||||
|
||||
describe "getDocument", ->
|
||||
|
@ -33,7 +34,7 @@ describe "DocumentController", ->
|
|||
|
||||
describe "when the document exists", ->
|
||||
beforeEach ->
|
||||
@ProjectEntityHandler.getDoc = sinon.stub().callsArgWith(2, null, @doc_lines, @rev, @version)
|
||||
@ProjectEntityHandler.getDoc = sinon.stub().callsArgWith(2, null, @doc_lines, @rev, @version, @ranges)
|
||||
@DocumentController.getDocument(@req, @res, @next)
|
||||
|
||||
it "should get the document from Mongo", ->
|
||||
|
@ -46,6 +47,7 @@ describe "DocumentController", ->
|
|||
@res.body.should.equal JSON.stringify
|
||||
lines: @doc_lines
|
||||
version: @version
|
||||
ranges: @ranges
|
||||
|
||||
describe "when the document doesn't exist", ->
|
||||
beforeEach ->
|
||||
|
@ -68,11 +70,12 @@ describe "DocumentController", ->
|
|||
@req.body =
|
||||
lines: @doc_lines
|
||||
version: @version
|
||||
ranges: @ranges
|
||||
@DocumentController.setDocument(@req, @res, @next)
|
||||
|
||||
it "should update the document in Mongo", ->
|
||||
@ProjectEntityHandler.updateDocLines
|
||||
.calledWith(@project_id, @doc_id, @doc_lines, @version)
|
||||
.calledWith(@project_id, @doc_id, @doc_lines, @version, @ranges)
|
||||
.should.equal true
|
||||
|
||||
it "should return a successful response", ->
|
||||
|
|
|
@ -382,7 +382,9 @@ describe 'ProjectEntityHandler', ->
|
|||
beforeEach ->
|
||||
@lines = ["mock", "doc", "lines"]
|
||||
@rev = 5
|
||||
@DocstoreManager.getDoc = sinon.stub().callsArgWith(3, null, @lines, @rev)
|
||||
@version = 42
|
||||
@ranges = {"mock": "ranges"}
|
||||
@DocstoreManager.getDoc = sinon.stub().callsArgWith(3, null, @lines, @rev, @version, @ranges)
|
||||
@ProjectEntityHandler.getDoc project_id, doc_id, @callback
|
||||
|
||||
it "should call the docstore", ->
|
||||
|
@ -391,7 +393,7 @@ describe 'ProjectEntityHandler', ->
|
|||
.should.equal true
|
||||
|
||||
it "should call the callback with the lines, version and rev", ->
|
||||
@callback.calledWith(null, @lines, @rev).should.equal true
|
||||
@callback.calledWith(null, @lines, @rev, @version, @ranges).should.equal true
|
||||
|
||||
describe 'addDoc', ->
|
||||
beforeEach ->
|
||||
|
@ -590,6 +592,7 @@ describe 'ProjectEntityHandler', ->
|
|||
_id: doc_id
|
||||
}
|
||||
@version = 42
|
||||
@ranges = {"mock":"ranges"}
|
||||
@ProjectGetter.getProjectWithoutDocLines = sinon.stub().callsArgWith(1, null, @project)
|
||||
@projectLocator.findElement = sinon.stub().callsArgWith(1, null, @doc, {fileSystem: @path})
|
||||
@tpdsUpdateSender.addDoc = sinon.stub().callsArg(1)
|
||||
|
@ -599,7 +602,7 @@ describe 'ProjectEntityHandler', ->
|
|||
describe "when the doc has been modified", ->
|
||||
beforeEach ->
|
||||
@DocstoreManager.updateDoc = sinon.stub().yields(null, true, @rev = 5)
|
||||
@ProjectEntityHandler.updateDocLines project_id, doc_id, @lines, @version, @callback
|
||||
@ProjectEntityHandler.updateDocLines project_id, doc_id, @lines, @version, @ranges, @callback
|
||||
|
||||
it "should get the project without doc lines", ->
|
||||
@ProjectGetter.getProjectWithoutDocLines
|
||||
|
@ -617,7 +620,7 @@ describe 'ProjectEntityHandler', ->
|
|||
|
||||
it "should update the doc in the docstore", ->
|
||||
@DocstoreManager.updateDoc
|
||||
.calledWith(project_id, doc_id, @lines, @version)
|
||||
.calledWith(project_id, doc_id, @lines, @version, @ranges)
|
||||
.should.equal true
|
||||
|
||||
it "should mark the project as updated", ->
|
||||
|
@ -642,7 +645,7 @@ describe 'ProjectEntityHandler', ->
|
|||
describe "when the doc has not been modified", ->
|
||||
beforeEach ->
|
||||
@DocstoreManager.updateDoc = sinon.stub().yields(null, false, @rev = 5)
|
||||
@ProjectEntityHandler.updateDocLines project_id, doc_id, @lines, @version, @callback
|
||||
@ProjectEntityHandler.updateDocLines project_id, doc_id, @lines, @version, @ranges, @callback
|
||||
|
||||
it "should not mark the project as updated", ->
|
||||
@projectUpdater.markAsUpdated.called.should.equal false
|
||||
|
@ -656,7 +659,7 @@ describe 'ProjectEntityHandler', ->
|
|||
describe "when the project is not found", ->
|
||||
beforeEach ->
|
||||
@ProjectGetter.getProjectWithoutDocLines = sinon.stub().callsArgWith(1, null, null)
|
||||
@ProjectEntityHandler.updateDocLines project_id, doc_id, @lines, @version, @callback
|
||||
@ProjectEntityHandler.updateDocLines project_id, doc_id, @lines, @ranges, @version, @callback
|
||||
|
||||
it "should return a not found error", ->
|
||||
@callback.calledWith(new Errors.NotFoundError()).should.equal true
|
||||
|
@ -664,7 +667,7 @@ describe 'ProjectEntityHandler', ->
|
|||
describe "when the doc is not found", ->
|
||||
beforeEach ->
|
||||
@projectLocator.findElement = sinon.stub().callsArgWith(1, null, null, null)
|
||||
@ProjectEntityHandler.updateDocLines project_id, doc_id, @lines, @version, @callback
|
||||
@ProjectEntityHandler.updateDocLines project_id, doc_id, @lines, @ranges, @version, @callback
|
||||
|
||||
it "should log out the error", ->
|
||||
@logger.error
|
||||
|
|
Loading…
Reference in a new issue