From 7a9577e081e1a2ae6a160cd97af78ac322a6ac86 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Mon, 30 Nov 2015 15:17:11 +0000 Subject: [PATCH] only flush to track-changes when ops are queued --- .../document-updater/app/coffee/DocumentManager.coffee | 2 +- .../document-updater/app/coffee/RedisManager.coffee | 3 +++ .../app/coffee/TrackChangesManager.coffee | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/services/document-updater/app/coffee/DocumentManager.coffee b/services/document-updater/app/coffee/DocumentManager.coffee index 81fa0aa66c..c7aa1e565a 100644 --- a/services/document-updater/app/coffee/DocumentManager.coffee +++ b/services/document-updater/app/coffee/DocumentManager.coffee @@ -91,7 +91,7 @@ module.exports = DocumentManager = logger.log project_id: project_id, doc_id: doc_id, version: version, "flushing doc" PersistenceManager.setDoc project_id, doc_id, lines, version, (error) -> return callback(error) if error? - TrackChangesManager.flushDocChanges project_id, doc_id, (error) -> + TrackChangesManager.flushDocChangesIfNeeded project_id, doc_id, (error) -> return callback(error) if error? callback null diff --git a/services/document-updater/app/coffee/RedisManager.coffee b/services/document-updater/app/coffee/RedisManager.coffee index d280de1cea..b0a33aa734 100644 --- a/services/document-updater/app/coffee/RedisManager.coffee +++ b/services/document-updater/app/coffee/RedisManager.coffee @@ -171,6 +171,9 @@ module.exports = RedisManager = [length, _] = results callback(error, length) + getUncompressedHistoryOpLength: (doc_id, callback = (error, length) ->) -> + rclient.llen keys.uncompressedHistoryOp(doc_id: doc_id), callback + getDocOpsLength: (doc_id, callback = (error, length) ->) -> rclient.llen keys.docOps(doc_id: doc_id), callback diff --git a/services/document-updater/app/coffee/TrackChangesManager.coffee b/services/document-updater/app/coffee/TrackChangesManager.coffee index 90cba86b36..86bb329f9b 100644 --- a/services/document-updater/app/coffee/TrackChangesManager.coffee +++ b/services/document-updater/app/coffee/TrackChangesManager.coffee @@ -5,6 +5,16 @@ RedisManager = require "./RedisManager" crypto = require("crypto") module.exports = TrackChangesManager = + + flushDocChangesIfNeeded: (project_id, doc_id, callback = (error) ->) -> + RedisManager.getUncompressedHistoryOpLength doc_id, (error, length) -> + return callback(error) if error? + if length > 0 + # only make request to track changes if there are queued ops + TrackChangesManager.flushDocChanges project_id, doc_id, callback + else + callback() + flushDocChanges: (project_id, doc_id, callback = (error) ->) -> if !settings.apis?.trackchanges? logger.warn doc_id: doc_id, "track changes API is not configured, so not flushing"