replace docs collection to DocstoreHandler

This commit is contained in:
Henrique Dias 2015-08-24 10:38:31 -03:00
parent 04ec45529f
commit 98ce03b2f2
4 changed files with 27 additions and 9 deletions

View file

@ -1,20 +1,18 @@
MongoManager = require "./MongoManager"
MongoAWS = require "./MongoAWS"
LockManager = require "./LockManager"
DocstoreHandler = require "./DocstoreHandler"
logger = require "logger-sharelatex"
_ = require "underscore"
async = require "async"
settings = require("settings-sharelatex")
request = require("request")
crypto = require("crypto")
thirtySeconds = 30 * 1000
module.exports = DocArchiveManager =
archiveAllDocsChanges: (project_id, callback = (error, docs) ->) ->
if settings.filestore?.backend != "s3"
return callback(null)
MongoManager.getProjectsDocs project_id, (error, docs) ->
DocstoreHandler.getAllDocs project_id, (error, docs) ->
if error?
return callback(error)
else if !docs?
@ -46,7 +44,7 @@ module.exports = DocArchiveManager =
unArchiveAllDocsChanges: (project_id, callback = (error, docs) ->) ->
if settings.filestore?.backend != "s3"
return callback(null)
MongoManager.getProjectsDocs project_id, (error, docs) ->
DocstoreHandler.getAllDocs project_id, (error, docs) ->
if error?
return callback(error)
else if !docs?
@ -65,3 +63,6 @@ module.exports = DocArchiveManager =
MongoManager.markDocHistoryAsUnarchived doc_id, (error) ->
return callback(error) if error?
callback()
getProjectsDocs: (project_id, callback)->
db.docs.find project_id: ObjectId(project_id.toString()), {}, callback

View file

@ -0,0 +1,20 @@
request = require("request").defaults(jar: false)
logger = require "logger-sharelatex"
settings = require "settings-sharelatex"
module.exports = DocstoreHandler =
getAllDocs: (project_id, callback = (error) ->) ->
logger.log project_id: project_id, "getting all docs for project in docstore api"
url = "#{settings.apis.docstore.url}/project/#{project_id}/doc"
request.get {
url: url
json: true
}, (error, res, docs) ->
return callback(error) if error?
if 200 <= res.statusCode < 300
callback(null, docs)
else
error = new Error("docstore api responded with non-success code: #{res.statusCode}")
logger.error err: error, project_id: project_id, "error getting all docs from docstore"
callback(error)

View file

@ -131,9 +131,6 @@ module.exports = MongoManager =
db.docHistoryStats.ensureIndex { doc_id: 1 }, { background: true }
db.docHistoryStats.ensureIndex { updates: -1, doc_id: 1 }, { background: true }
getProjectsDocs: (project_id, callback)->
db.docs.find project_id: ObjectId(project_id.toString()), {}, callback
getDocChangesCount: (doc_id, callback)->
db.docHistory.count { doc_id : doc_id, inS3 : { $exists : false }}, {}, callback

View file

@ -1,6 +1,6 @@
Settings = require "settings-sharelatex"
mongojs = require "mongojs"
db = mongojs.connect(Settings.mongo.url, ["docHistory", "projectHistoryMetaData", "docHistoryStats", "docs"])
db = mongojs.connect(Settings.mongo.url, ["docHistory", "projectHistoryMetaData", "docHistoryStats"])
module.exports =
db: db
ObjectId: mongojs.ObjectId