mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
optimistically load all docs
This commit is contained in:
parent
e10d09d040
commit
b9b0596d83
2 changed files with 44 additions and 10 deletions
|
@ -55,17 +55,28 @@ module.exports = DocManager =
|
||||||
return callback(err)
|
return callback(err)
|
||||||
callback(err, doc)
|
callback(err, doc)
|
||||||
|
|
||||||
getAllNonDeletedDocs: (project_id, filter, callback = (error, docs) ->) ->
|
_getAllDocs: (project_id, filter, callback = (error, docs) ->) ->
|
||||||
DocArchive.unArchiveAllDocs project_id, (error) ->
|
MongoManager.getProjectsDocs project_id, {include_deleted: false}, filter, (error, docs) ->
|
||||||
if error?
|
if err?
|
||||||
return callback(error)
|
return callback(error)
|
||||||
MongoManager.getProjectsDocs project_id, {include_deleted: false}, filter, (error, docs) ->
|
else if !docs?
|
||||||
if err?
|
return callback new Errors.NotFoundError("No docs for project #{project_id}")
|
||||||
return callback(error)
|
else
|
||||||
else if !docs?
|
callback(null, docs)
|
||||||
return callback new Errors.NotFoundError("No docs for project #{project_id}")
|
|
||||||
else
|
getAllNonDeletedDocs: (project_id, filter, callback = (error, docs) ->) ->
|
||||||
return callback(null, docs)
|
DocManager._getAllDocs project_id, filter, (error, docs) ->
|
||||||
|
return callback(error) if error?
|
||||||
|
# check if any docs have been archived
|
||||||
|
docsInS3 = (doc for doc in docs when doc?.inS3)
|
||||||
|
if docsInS3.length > 0
|
||||||
|
DocArchive.unArchiveAllDocs project_id, (error) ->
|
||||||
|
if error?
|
||||||
|
logger.err err:error, project_id:project_id, "error unarchiving docs"
|
||||||
|
return callback(error)
|
||||||
|
DocManager._getAllDocs project_id, filter, callback
|
||||||
|
else
|
||||||
|
return callback(null, docs)
|
||||||
|
|
||||||
updateDoc: (project_id, doc_id, lines, version, ranges, callback = (error, modified, rev) ->) ->
|
updateDoc: (project_id, doc_id, lines, version, ranges, callback = (error, modified, rev) ->) ->
|
||||||
if !lines? or !version? or !ranges?
|
if !lines? or !version? or !ranges?
|
||||||
|
|
|
@ -215,6 +215,29 @@ describe "DocManager", ->
|
||||||
.calledWith(new Errors.NotFoundError("No docs for project #{@project_id}"))
|
.calledWith(new Errors.NotFoundError("No docs for project #{@project_id}"))
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
|
describe "when there are some archived docs for the project", ->
|
||||||
|
beforeEach ->
|
||||||
|
@stubs = [{ _id: @doc_id, project_id: @project_id, inS3:true }]
|
||||||
|
@docs = [{ _id: @doc_id, project_id: @project_id, lines: ["mock-lines"] }]
|
||||||
|
@MongoManager.getProjectsDocs = sinon.stub()
|
||||||
|
.callsArgWith(3, null, @stubs) # first call
|
||||||
|
.callsArgWith(3, null, @docs) # second call (after unarchiving)
|
||||||
|
@DocArchiveManager.unArchiveAllDocs = sinon.stub().callsArgWith(1, null)
|
||||||
|
@DocManager.getAllNonDeletedDocs @project_id, @filter, @callback
|
||||||
|
|
||||||
|
it "should get the project from the database", ->
|
||||||
|
@MongoManager.getProjectsDocs
|
||||||
|
.calledWith(@project_id, {include_deleted: false}, @filter)
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
|
it "should unarchive the documents", ->
|
||||||
|
@DocArchiveManager.unArchiveAllDocs
|
||||||
|
.calledWith(@project_id)
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
|
it "should return the docs", ->
|
||||||
|
@callback.calledWith(null, @docs).should.equal true
|
||||||
|
|
||||||
describe "deleteDoc", ->
|
describe "deleteDoc", ->
|
||||||
describe "when the doc exists", ->
|
describe "when the doc exists", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
|
Loading…
Reference in a new issue