overleaf/services/track-changes/app/coffee/HistoryManager.coffee
2014-02-24 17:43:27 +00:00

18 lines
775 B
CoffeeScript

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()