overleaf/services/track-changes/app/coffee/HistoryManager.coffee

19 lines
775 B
CoffeeScript
Raw Normal View History

MongoManager = require "./MongoManager"
UpdateCompressor = require "./UpdateCompressor"
logger = require "logger-sharelatex"
module.exports = HistoryManager =
compressAndSaveRawUpdates: (doc_id, rawUpdates, callback = (error) ->) ->
length = rawUpdates.length
if length == 0
return callback()
MongoManager.popLastCompressedUpdate doc_id, (error, lastCompressedUpdate) ->
return callback(error) if error?
compressedUpdates = UpdateCompressor.compressRawUpdates lastCompressedUpdate, rawUpdates
MongoManager.insertCompressedUpdates doc_id, compressedUpdates, (error) ->
return callback(error) if error?
logger.log doc_id: doc_id, rawUpdatesLength: length, compressedUpdatesLength: compressedUpdates.length, "compressed doc updates"
callback()