From 4a82dfe61864e11da4a4a6f6621adbe93bc106cd Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Thu, 17 Dec 2015 16:28:02 +0000 Subject: [PATCH] add setting trackchanges.continueOnError to allow recovery from missing ops --- services/track-changes/app/coffee/UpdatesManager.coffee | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/services/track-changes/app/coffee/UpdatesManager.coffee b/services/track-changes/app/coffee/UpdatesManager.coffee index ffc2cef19a..c38fb770c4 100644 --- a/services/track-changes/app/coffee/UpdatesManager.coffee +++ b/services/track-changes/app/coffee/UpdatesManager.coffee @@ -8,6 +8,7 @@ logger = require "logger-sharelatex" async = require "async" DocArchiveManager = require "./DocArchiveManager" _ = require "underscore" +Settings = require "settings-sharelatex" module.exports = UpdatesManager = compressAndSaveRawUpdates: (project_id, doc_id, rawUpdates, temporary, callback = (error) ->) -> @@ -38,7 +39,10 @@ module.exports = UpdatesManager = if rawUpdates[0]? and rawUpdates[0].v != lastVersion + 1 error = new Error("Tried to apply raw op at version #{rawUpdates[0].v} to last compressed update with version #{lastVersion}") logger.error err: error, doc_id: doc_id, project_id: project_id, "inconsistent doc versions" - return callback error + if Settings.trackchanges?.continueOnError and rawUpdates[0].v > lastVersion + 1 + # we have lost some ops - continue to write into the database, we can't recover at this point + else + return callback error compressedUpdates = UpdateCompressor.compressRawUpdates lastCompressedUpdate, rawUpdates