diff --git a/services/track-changes/app/coffee/DocArchiveManager.coffee b/services/track-changes/app/coffee/DocArchiveManager.coffee index 05d8430984..c69509ab10 100644 --- a/services/track-changes/app/coffee/DocArchiveManager.coffee +++ b/services/track-changes/app/coffee/DocArchiveManager.coffee @@ -36,20 +36,25 @@ module.exports = DocArchiveManager = logger.log {project_id, doc_id}, "document history is empty, not archiving" return callback() else - MongoManager.getLastCompressedUpdate doc_id, (error, update) -> + MongoManager.getArchivedDocChanges doc_id, (error, count) -> return callback(error) if error? - MongoManager.markDocHistoryAsArchiveInProgress doc_id, update, (error) -> + if count != 0 + logger.log {project_id, doc_id}, "document history contains archived entries, not archiving" + return callback() + MongoManager.getLastCompressedUpdate doc_id, (error, update) -> return callback(error) if error? - MongoAWS.archiveDocHistory project_id, doc_id, (error) -> - if error? - MongoManager.clearDocHistoryAsArchiveInProgress doc_id, update, (err) -> - return callback(err) if err? - callback(error) - else - logger.log doc_id:doc_id, project_id:project_id, "exported document to S3" - MongoManager.markDocHistoryAsArchived doc_id, update, (error) -> - return callback(error) if error? - callback() + MongoManager.markDocHistoryAsArchiveInProgress doc_id, update, (error) -> + return callback(error) if error? + MongoAWS.archiveDocHistory project_id, doc_id, (error) -> + if error? + MongoManager.clearDocHistoryAsArchiveInProgress doc_id, update, (err) -> + return callback(err) if err? + callback(error) + else + logger.log doc_id:doc_id, project_id:project_id, "exported document to S3" + MongoManager.markDocHistoryAsArchived doc_id, update, (error) -> + return callback(error) if error? + callback() unArchiveAllDocsChanges: (project_id, callback = (error, docs) ->) -> DocstoreHandler.getAllDocs project_id, (error, docs) -> diff --git a/services/track-changes/app/coffee/MongoManager.coffee b/services/track-changes/app/coffee/MongoManager.coffee index c31d466655..7fe7d2ab4f 100644 --- a/services/track-changes/app/coffee/MongoManager.coffee +++ b/services/track-changes/app/coffee/MongoManager.coffee @@ -144,7 +144,7 @@ module.exports = MongoManager = 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 + db.docHistory.count { doc_id: ObjectId(doc_id.toString()) , inS3: { $exists: true }}, {}, callback markDocHistoryAsArchiveInProgress: (doc_id, update, callback) -> db.docHistory.update { _id: update._id }, { $set : { inS3 : false } }, callback