mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-06 15:12:07 +00:00
added support for cleaning old expired ops in packs
This commit is contained in:
parent
5c4afd5303
commit
1811ac2145
2 changed files with 35 additions and 1 deletions
|
@ -339,3 +339,34 @@ module.exports = PackManager =
|
|||
), result)
|
||||
else
|
||||
callback(err, result)
|
||||
|
||||
deleteExpiredPackOps: (docs, callback) ->
|
||||
now = Date.now()
|
||||
toRemove = []
|
||||
toUpdate = []
|
||||
docs.forEach (d,i) ->
|
||||
if d.pack?
|
||||
newPack = d.pack.filter (op) ->
|
||||
if op.expiresAt? then op.expiresAt > now else true
|
||||
if newPack.length == 0
|
||||
toRemove.push d
|
||||
else if newPack.length < d.pack.length
|
||||
# adjust the pack properties
|
||||
d.pack = newPack
|
||||
first = d.pack[0]
|
||||
last = d.pack[d.pack.length - 1]
|
||||
d.v_end = last.v
|
||||
d.meta.start_ts = first.meta.start_ts
|
||||
d.meta.end_ts = last.meta.end_ts
|
||||
toUpdate.push d
|
||||
if toRemove.length or toUpdate.length
|
||||
bulk = db.docHistory.initializeOrderedBulkOp()
|
||||
toRemove.forEach (pack) ->
|
||||
console.log "would remove", pack
|
||||
#bulk.find({_id:pack._id}).removeOne()
|
||||
toUpdate.forEach (pack) ->
|
||||
console.log "would update", pack
|
||||
#bulk.find({_id:pack._id}).updateOne(pack);
|
||||
bulk.execute callback
|
||||
else
|
||||
callback()
|
||||
|
|
|
@ -45,7 +45,10 @@ getDocHistory = (doc_id, callback) ->
|
|||
util.log "checking history for #{doc_id}"
|
||||
PackManager.checkHistory docs, (err) ->
|
||||
return callback(err) if err?
|
||||
callback err, docs
|
||||
callback(err, docs)
|
||||
#PackManager.deleteExpiredPackOps docs, (err) ->
|
||||
# return callback(err) if err?
|
||||
# callback err, docs
|
||||
|
||||
safeInsert = (packObj, callback) ->
|
||||
if shutdownRequested
|
||||
|
|
Loading…
Add table
Reference in a new issue