 {db, ObjectId, BSON} = require "./mongojs"
 logger = require "logger-sharelatex"
 LockManager = require "./LockManager"
+
+DAYS = 24 * 3600 * 1000 # one day in milliseconds
 
 module.exports = PackManager =
 	# The following functions implement methods like a mongo find, but

				end_ts: last.meta.end_ts
			v: first.v
			v_end: last.v
		logger.log {project_id, doc_id, newUpdates}, "inserting updates into new pack"
		db.docHistory.insert newPack, callback



	flushCompressedUpdates:	(project_id, doc_id, lastUpdate, newUpdates, temporary, callback = (error) ->) ->
		return callback() if newUpdates.length == 0
		if lastUpdate? and not (temporary and ((Date.now() - lastUpdate.meta?.start_ts) > 1 * DAYS))
			PackManager.appendUpdatesToExistingPack project_id, doc_id, lastUpdate, newUpdates, temporary, callback
		else
			PackManager.insertUpdatesIntoNewPack project_id, doc_id, newUpdates, temporary, callback
