2014-02-24 12:43:27 -05:00
|
|
|
MongoManager = require "./MongoManager"
|
2014-01-27 11:26:58 -05:00
|
|
|
UpdateCompressor = require "./UpdateCompressor"
|
|
|
|
logger = require "logger-sharelatex"
|
|
|
|
|
|
|
|
module.exports = HistoryManager =
|
|
|
|
compressAndSaveRawUpdates: (doc_id, rawUpdates, callback = (error) ->) ->
|
|
|
|
length = rawUpdates.length
|
|
|
|
if length == 0
|
|
|
|
return callback()
|
|
|
|
|
2014-02-24 12:43:27 -05:00
|
|
|
MongoManager.popLastCompressedUpdate doc_id, (error, lastCompressedUpdate) ->
|
2014-01-27 11:26:58 -05:00
|
|
|
return callback(error) if error?
|
|
|
|
compressedUpdates = UpdateCompressor.compressRawUpdates lastCompressedUpdate, rawUpdates
|
2014-02-24 12:43:27 -05:00
|
|
|
MongoManager.insertCompressedUpdates doc_id, compressedUpdates, (error) ->
|
2014-01-27 11:26:58 -05:00
|
|
|
return callback(error) if error?
|
|
|
|
logger.log doc_id: doc_id, rawUpdatesLength: length, compressedUpdatesLength: compressedUpdates.length, "compressed doc updates"
|
|
|
|
callback()
|
|
|
|
|