|
|
@@ -7,7 +7,7 @@ module.exports = HistoryManager =
|
|
|
flushChangesAsync: (project_id, doc_id) ->
|
|
|
HistoryManager._flushDocChangesAsync project_id, doc_id
|
|
|
if Settings.apis?.project_history?.enabled
|
|
|
- HistoryManager._flushProjectChangesAsync project_id
|
|
|
+ HistoryManager.flushProjectChangesAsync project_id
|
|
|
|
|
|
_flushDocChangesAsync: (project_id, doc_id) ->
|
|
|
if !Settings.apis?.trackchanges?
|
|
|
@@ -22,7 +22,7 @@ module.exports = HistoryManager =
|
|
|
else if res.statusCode < 200 and res.statusCode >= 300
|
|
|
logger.error { doc_id, project_id }, "track changes api returned a failure status code: #{res.statusCode}"
|
|
|
|
|
|
- _flushProjectChangesAsync: (project_id) ->
|
|
|
+ flushProjectChangesAsync: (project_id) ->
|
|
|
return if !Settings.apis?.project_history?
|
|
|
|
|
|
url = "#{Settings.apis.project_history.url}/project/#{project_id}/flush"
|
|
|
@@ -42,7 +42,10 @@ module.exports = HistoryManager =
|
|
|
|
|
|
if Settings.apis?.project_history?.enabled
|
|
|
if HistoryManager._shouldFlushHistoryOps(project_ops_length, ops, HistoryManager.FLUSH_PROJECT_EVERY_N_OPS)
|
|
|
- HistoryManager.flushProjectChanges project_id, project_ops_length
|
|
|
+ # Do this in the background since it uses HTTP and so may be too
|
|
|
+ # slow to wait for when processing a doc update.
|
|
|
+ logger.log { project_ops_length, project_id }, "flushing project history api"
|
|
|
+ HistoryManager.flushProjectChangesAsync project_id
|
|
|
|
|
|
HistoryRedisManager.recordDocHasHistoryOps project_id, doc_id, ops, (error) ->
|
|
|
return callback(error) if error?
|
|
|
@@ -53,19 +56,16 @@ module.exports = HistoryManager =
|
|
|
HistoryManager._flushDocChangesAsync project_id, doc_id
|
|
|
callback()
|
|
|
|
|
|
- flushProjectChanges: (project_id, project_ops_length) ->
|
|
|
- # Do this in the background since it uses HTTP and so may be too
|
|
|
- # slow to wait for when processing a doc update.
|
|
|
- logger.log { project_ops_length, project_id }, "flushing project history api"
|
|
|
- HistoryManager._flushProjectChangesAsync project_id
|
|
|
-
|
|
|
_shouldFlushHistoryOps: (length, ops, threshold) ->
|
|
|
+ return HistoryManager.shouldFlushHistoryOps(length, ops.length, threshold)
|
|
|
+
|
|
|
+ shouldFlushHistoryOps: (length, ops_length, threshold) ->
|
|
|
return false if !length # don't flush unless we know the length
|
|
|
# We want to flush every 100 ops, i.e. 100, 200, 300, etc
|
|
|
# Find out which 'block' (i.e. 0-99, 100-199) we were in before and after pushing these
|
|
|
# ops. If we've changed, then we've gone over a multiple of 100 and should flush.
|
|
|
# (Most of the time, we will only hit 100 and then flushing will put us back to 0)
|
|
|
- previousLength = length - ops.length
|
|
|
+ previousLength = length - ops_length
|
|
|
prevBlock = Math.floor(previousLength / threshold)
|
|
|
newBlock = Math.floor(length / threshold)
|
|
|
return newBlock != prevBlock
|