|
@@ -3,6 +3,7 @@ DocumentManager = require "./DocumentManager"
|
|
|
async = require "async"
|
|
async = require "async"
|
|
|
logger = require "logger-sharelatex"
|
|
logger = require "logger-sharelatex"
|
|
|
Metrics = require "./Metrics"
|
|
Metrics = require "./Metrics"
|
|
|
|
|
+Errors = require "./Errors"
|
|
|
|
|
|
|
|
module.exports = ProjectManager =
|
|
module.exports = ProjectManager =
|
|
|
flushProjectWithLocks: (project_id, _callback = (error) ->) ->
|
|
flushProjectWithLocks: (project_id, _callback = (error) ->) ->
|
|
@@ -57,29 +58,34 @@ module.exports = ProjectManager =
|
|
|
else
|
|
else
|
|
|
callback(null)
|
|
callback(null)
|
|
|
|
|
|
|
|
- getProjectDocs: (project_id, excludeVersions = {}, _callback = (error) ->) ->
|
|
|
|
|
|
|
+ getProjectDocs: (project_id, projectStateHash, excludeVersions = {}, _callback = (error) ->) ->
|
|
|
timer = new Metrics.Timer("projectManager.getProjectDocs")
|
|
timer = new Metrics.Timer("projectManager.getProjectDocs")
|
|
|
callback = (args...) ->
|
|
callback = (args...) ->
|
|
|
timer.done()
|
|
timer.done()
|
|
|
_callback(args...)
|
|
_callback(args...)
|
|
|
|
|
|
|
|
- RedisManager.getDocIdsInProject project_id, (error, doc_ids) ->
|
|
|
|
|
|
|
+ RedisManager.checkOrSetProjectState project_id, projectStateHash, (error, projectStateChanged) ->
|
|
|
return callback(error) if error?
|
|
return callback(error) if error?
|
|
|
- jobs = []
|
|
|
|
|
- docs = []
|
|
|
|
|
- for doc_id in doc_ids or []
|
|
|
|
|
- do (doc_id) ->
|
|
|
|
|
- jobs.push (cb) ->
|
|
|
|
|
- # check the doc version first
|
|
|
|
|
- RedisManager.getDocVersion doc_id, (error, version) ->
|
|
|
|
|
- return cb(error) if error?
|
|
|
|
|
- # skip getting the doc if we already have that version
|
|
|
|
|
- return cb() if version is excludeVersions[doc_id]
|
|
|
|
|
- # otherwise get the doc lines from redis
|
|
|
|
|
- RedisManager.getDocLines doc_id, (error, lines) ->
|
|
|
|
|
- return cb(error) if error?
|
|
|
|
|
- docs.push {_id: doc_id, lines: lines, rev: version}
|
|
|
|
|
- cb()
|
|
|
|
|
- async.series jobs, (error) ->
|
|
|
|
|
|
|
+ # we can't return docs if project structure has changed
|
|
|
|
|
+ return callback Errors.ProjectStateChangedError("project state changed") if projectStateChanged
|
|
|
|
|
+ # project structure hasn't changed, return doc content from redis
|
|
|
|
|
+ RedisManager.getDocIdsInProject project_id, (error, doc_ids) ->
|
|
|
return callback(error) if error?
|
|
return callback(error) if error?
|
|
|
- callback(null, docs)
|
|
|
|
|
|
|
+ jobs = []
|
|
|
|
|
+ docs = []
|
|
|
|
|
+ for doc_id in doc_ids or []
|
|
|
|
|
+ do (doc_id) ->
|
|
|
|
|
+ jobs.push (cb) ->
|
|
|
|
|
+ # check the doc version first
|
|
|
|
|
+ RedisManager.getDocVersion doc_id, (error, version) ->
|
|
|
|
|
+ return cb(error) if error?
|
|
|
|
|
+ # skip getting the doc if we already have that version
|
|
|
|
|
+ return cb() if version is excludeVersions[doc_id]
|
|
|
|
|
+ # otherwise get the doc lines from redis
|
|
|
|
|
+ RedisManager.getDocLines doc_id, (error, lines) ->
|
|
|
|
|
+ return cb(error) if error?
|
|
|
|
|
+ docs.push {_id: doc_id, lines: lines, rev: version}
|
|
|
|
|
+ cb()
|
|
|
|
|
+ async.series jobs, (error) ->
|
|
|
|
|
+ return callback(error) if error?
|
|
|
|
|
+ callback(null, docs)
|