fix inS3 propagation

This commit is contained in:
Henrique Dias
2015-08-24 12:19:19 -03:00
parent 1ccba422c8
commit fcbe4aa925
2 changed files with 16 additions and 8 deletions
@@ -1,6 +1,7 @@
{db, ObjectId} = require "./mongojs"
PackManager = require "./PackManager"
async = require "async"
logger = require "logger-sharelatex"
module.exports = MongoManager =
getLastCompressedUpdate: (doc_id, callback = (error, update) ->) ->
@@ -47,7 +48,6 @@ module.exports = MongoManager =
insertCompressedUpdate: (project_id, doc_id, update, temporary, callback = (error) ->) ->
inS3 = update.inS3?
update = {
doc_id: ObjectId(doc_id.toString())
project_id: ObjectId(project_id.toString())
@@ -55,8 +55,6 @@ module.exports = MongoManager =
meta: update.meta
v: update.v
}
if inS3?
update.inS3 = true
if temporary
seconds = 1000
@@ -132,18 +130,25 @@ module.exports = MongoManager =
db.docHistoryStats.ensureIndex { updates: -1, doc_id: 1 }, { background: true }
getDocChangesCount: (doc_id, callback)->
db.docHistory.count { doc_id : doc_id, inS3 : { $exists : false }}, {}, callback
db.docHistory.count { doc_id : ObjectId(doc_id.toString()), inS3 : { $exists : false }}, {}, callback
getArchivedDocChanges: (doc_id, callback)->
db.docHistory.count { doc_id: ObjectId(doc_id.toString()) , inS3: true }, {}, callback
remarkDocHistoryAsArchived: (doc_id, callback)->
logger.log doc_id: doc_id, "remarkDocHistoryAsArchived"
MongoManager.getLastCompressedUpdate doc_id, (error, update) ->
db.docHistory.update { _id: update._id }, { $set : { inS3 : true } }, (error)->
return callback(error) if error?
callback(error)
markDocHistoryAsArchived: (doc_id, update, callback)->
db.docHistory.update { v: update.v }, { $set : { inS3 : true } }, (error)->
db.docHistory.update { _id: update._id }, { $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)->
db.docHistory.remove { doc_id : ObjectId(doc_id.toString()), inS3 : { $exists : false }, v: { $lt : update.v }, expiresAt: {$exists : false} }, (error)->
return callback(error) if error?
callback(error)
markDocHistoryAsUnarchived: (doc_id, callback)->
db.docHistory.update { doc_id: doc_id }, { $unset : { inS3 : true } }, { multi: true }, (error)->
db.docHistory.update { doc_id: ObjectId(doc_id.toString()) }, { $unset : { inS3 : true } }, { multi: true }, (error)->
callback(error)
@@ -36,7 +36,10 @@ module.exports = UpdatesManager =
MongoManager.insertCompressedUpdates project_id, doc_id, compressedUpdates, temporary,(error) ->
return callback(error) if error?
logger.log project_id: project_id, doc_id: doc_id, rawUpdatesLength: length, compressedUpdatesLength: compressedUpdates.length, "compressed doc updates"
callback()
if lastCompressedUpdate.inS3?
MongoManager.remarkDocHistoryAsArchived doc_id, callback
else
callback()
REDIS_READ_BATCH_SIZE: 100
processUncompressedUpdates: (project_id, doc_id, callback = (error) ->) ->