From 04ec45529fa96a7dd485e6baab1703726cded0f3 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Tue, 18 Aug 2015 17:11:19 -0300 Subject: [PATCH] restore updates from S3 when exists fix: avoid rearchiving --- .../track-changes/app/coffee/MongoManager.coffee | 2 +- .../track-changes/app/coffee/UpdatesManager.coffee | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/services/track-changes/app/coffee/MongoManager.coffee b/services/track-changes/app/coffee/MongoManager.coffee index 9163da8009..44e1335e8c 100644 --- a/services/track-changes/app/coffee/MongoManager.coffee +++ b/services/track-changes/app/coffee/MongoManager.coffee @@ -135,7 +135,7 @@ module.exports = MongoManager = db.docs.find project_id: ObjectId(project_id.toString()), {}, callback getDocChangesCount: (doc_id, callback)-> - db.docHistory.count doc_id: ObjectId(doc_id.toString()), {}, callback + db.docHistory.count { doc_id : doc_id, inS3 : { $exists : false }}, {}, callback getArchivedDocChanges: (doc_id, callback)-> db.docHistory.count { doc_id: ObjectId(doc_id.toString()) , inS3: true }, {}, callback diff --git a/services/track-changes/app/coffee/UpdatesManager.coffee b/services/track-changes/app/coffee/UpdatesManager.coffee index 1fbfe53d7e..c104ceed7a 100644 --- a/services/track-changes/app/coffee/UpdatesManager.coffee +++ b/services/track-changes/app/coffee/UpdatesManager.coffee @@ -95,9 +95,17 @@ module.exports = UpdatesManager = getProjectUpdates: (project_id, options = {}, callback = (error, updates) ->) -> UpdatesManager.processUncompressedUpdatesForProject project_id, (error) -> return callback(error) if error? - DocArchiveManager.unArchiveAllDocsChanges project_id, (error) -> - return callback(error,null) if error? - MongoManager.getProjectUpdates project_id, options, callback + MongoManager.getProjectUpdates project_id, options, (error, updates) -> + jobs = [] + for update in updates + if update.inS3? + do (update) -> + jobs.push (callback) -> DocArchiveManager.unArchiveDocChanges update.project_id, update.doc_id, callback + if jobs.length? + async.series jobs, (err) -> + MongoManager.getProjectUpdates project_id, options, callback + else + callback(error, updates) getProjectUpdatesWithUserInfo: (project_id, options = {}, callback = (error, updates) ->) -> UpdatesManager.getProjectUpdates project_id, options, (error, updates) ->