mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-05 01:26:55 +00:00
expire temporary packs and roll over to a new pack each day
This commit is contained in:
parent
5e830cbbdb
commit
0ba00a9eb7
1 changed files with 7 additions and 1 deletions
|
@ -4,6 +4,8 @@ _ = require "underscore"
|
|||
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
|
||||
# expands any documents containing a 'pack' field into multiple
|
||||
|
@ -476,7 +478,7 @@ module.exports = PackManager =
|
|||
|
||||
flushCompressedUpdates: (project_id, doc_id, lastUpdate, newUpdates, temporary, callback = (error) ->) ->
|
||||
return callback() if newUpdates.length == 0
|
||||
if lastUpdate?
|
||||
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
|
||||
|
@ -497,6 +499,8 @@ module.exports = PackManager =
|
|||
end_ts: last.meta.end_ts
|
||||
v: first.v
|
||||
v_end: last.v
|
||||
if temporary
|
||||
newPack.expiresAt = new Date(Date.now() + 7 * DAYS)
|
||||
logger.log {project_id, doc_id, newUpdates}, "inserting updates into new pack"
|
||||
db.docHistory.insert newPack, callback
|
||||
|
||||
|
@ -519,6 +523,8 @@ module.exports = PackManager =
|
|||
$set:
|
||||
"meta.end_ts": last.meta.end_ts
|
||||
"v_end": last.v
|
||||
if lastUpdate.expiresAt and temporary
|
||||
update.$set.expiresAt = new Date(Date.now() + 7 * DAYS)
|
||||
logger.log {project_id, doc_id, lastUpdate, newUpdates}, "appending updates to existing pack"
|
||||
db.docHistory.findAndModify {query, update}, callback
|
||||
|
||||
|
|
Loading…
Reference in a new issue