mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Archive changes, care about: versioin, expiresAt and Lock
This commit is contained in:
parent
6bc9c9010a
commit
fd4afb3574
3 changed files with 21 additions and 13 deletions
|
@ -1,5 +1,6 @@
|
|||
MongoManager = require "./MongoManager"
|
||||
MongoAWS = require "./MongoAWS"
|
||||
LockManager = require "./LockManager"
|
||||
logger = require "logger-sharelatex"
|
||||
_ = require "underscore"
|
||||
async = require "async"
|
||||
|
@ -19,20 +20,28 @@ module.exports = DocArchiveManager =
|
|||
else if !docs?
|
||||
return callback new Error("No docs for project #{project_id}")
|
||||
jobs = _.map docs, (doc) ->
|
||||
(cb)-> DocArchiveManager.archiveDocChanges project_id, doc._id, cb
|
||||
(cb)-> DocArchiveManager.archiveDocChangesWithLock project_id, doc._id, cb
|
||||
async.series jobs, callback
|
||||
|
||||
archiveDocChangesWithLock: (project_id, doc_id, callback = (error) ->) ->
|
||||
LockManager.runWithLock(
|
||||
"HistoryArchiveLock:#{doc_id}",
|
||||
(releaseLock) ->
|
||||
DocArchiveManager.archiveDocChanges project_id, doc_id, releaseLock
|
||||
callback
|
||||
)
|
||||
|
||||
archiveDocChanges: (project_id, doc_id, callback)->
|
||||
MongoManager.getDocChangesCount doc_id, (error, count) ->
|
||||
if count == 0
|
||||
return callback()
|
||||
else
|
||||
MongoAWS.archiveDocHistory project_id, doc_id, (error) ->
|
||||
logger.log doc_id:doc_id, error: error, "mongoexport"
|
||||
MongoManager.markDocHistoryAsArchived doc_id, (error) ->
|
||||
return callback(error) if error?
|
||||
callback()
|
||||
MongoManager.getLastCompressedUpdate doc_id, (error, update) ->
|
||||
MongoAWS.archiveDocHistory project_id, doc_id, (error) ->
|
||||
logger.log doc_id:doc_id, error: error, "mongoexport"
|
||||
MongoManager.markDocHistoryAsArchived doc_id, update, (error) ->
|
||||
return callback(error) if error?
|
||||
callback()
|
||||
|
||||
unArchiveAllDocsChanges: (project_id, callback = (error, docs) ->) ->
|
||||
if settings.filestore?.backend != "s3"
|
||||
|
|
|
@ -33,7 +33,7 @@ module.exports = MongoAWS =
|
|||
args.push '-c'
|
||||
args.push 'docHistory'
|
||||
args.push '-q'
|
||||
args.push "{doc_id: ObjectId('#{doc_id}') }"
|
||||
args.push "{doc_id: ObjectId('#{doc_id}') , expiresAt: {$exists : false} }"
|
||||
args.push '-o'
|
||||
args.push filepath
|
||||
|
||||
|
|
|
@ -140,13 +140,12 @@ module.exports = MongoManager =
|
|||
getArchivedDocChanges: (doc_id, callback)->
|
||||
db.docHistory.count { doc_id: ObjectId(doc_id.toString()) , inS3: true }, {}, callback
|
||||
|
||||
markDocHistoryAsArchived: (doc_id, callback)->
|
||||
MongoManager.getLastCompressedUpdate doc_id, (error, update) ->
|
||||
db.docHistory.update { _id: update._id }, { $set : { inS3 : true } }, (error)->
|
||||
markDocHistoryAsArchived: (doc_id, update, callback)->
|
||||
db.docHistory.update { v: update.v }, { $set : { inS3 : true } }, (error)->
|
||||
return callback(error) if error?
|
||||
db.docHistory.remove { doc_id : doc_id, inS3 : { $exists : false }, v: { $lt : update.v }, expiresAt: {$exists : false} }, (error)->
|
||||
return callback(error) if error?
|
||||
db.docHistory.remove { doc_id : doc_id, inS3 : { $exists : false } }, (error)->
|
||||
return callback(error) if error?
|
||||
callback(error)
|
||||
callback(error)
|
||||
|
||||
markDocHistoryAsUnarchived: (doc_id, callback)->
|
||||
db.docHistory.update { doc_id: doc_id }, { $unset : { inS3 : true } }, { multi: true }, (error)->
|
||||
|
|
Loading…
Reference in a new issue