From 7af50503701bb6bc7487fe761f17c8dd7a56c7f4 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Wed, 16 Sep 2015 16:18:36 +0100 Subject: [PATCH] add lock to unarchive doc --- services/track-changes/app/coffee/DocArchiveManager.coffee | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/services/track-changes/app/coffee/DocArchiveManager.coffee b/services/track-changes/app/coffee/DocArchiveManager.coffee index 4f512bdc27..1ae3b22363 100644 --- a/services/track-changes/app/coffee/DocArchiveManager.coffee +++ b/services/track-changes/app/coffee/DocArchiveManager.coffee @@ -52,9 +52,14 @@ module.exports = DocArchiveManager = else if !docs? return callback new Error("No docs for project #{project_id}") jobs = _.map docs, (doc) -> - (cb)-> DocArchiveManager.unArchiveDocChanges project_id, doc._id, cb + (cb)-> DocArchiveManager.unArchiveDocChangesWithLock project_id, doc._id, cb async.parallelLimit jobs, 4, callback + unArchiveDocChangesWithLock: (project_id, doc_id, callback = (error) ->) -> + job = (releaseLock) -> + DocArchiveManager.unArchiveDocChanges project_id, doc_id, releaseLock + LockManager.runWithLock("HistoryLock:#{doc_id}", job, callback) + unArchiveDocChanges: (project_id, doc_id, callback)-> MongoManager.getArchivedDocChanges doc_id, (error, count) -> return callback(error) if error?