Compress all docs using compressHistory script

This commit is contained in:
James Allen 2013-08-09 11:36:19 +01:00
parent c5e7f14ba1
commit 64eb794c02
3 changed files with 41 additions and 28 deletions

View file

@ -30,10 +30,9 @@ module.exports = ConversionManager =
ConversionManager.getLastRawUpdateAndVersion doc_id, (error, rawUpdate, currentVersion, tailVersion) ->
return callback(error) if error?
if currentVersion - tailVersion > ConversionManager.OPS_TO_LEAVE
rawUpdates = ConcatManager.normalizeUpdate(rawUpdate)
if currentVersion - tailVersion > ConcatManager.OPS_TO_LEAVE
ConversonManager.getLatestCompressedUpdate doc_id, (error, lastCompressedUpdate) ->
ConversionManager.getLatestCompressedUpdate doc_id, (error, lastCompressedUpdate) ->
return callback(error) if error?
removeAndModifyPreviousCompressedUpdate = (callback, compressedUpdates) ->
@ -44,7 +43,7 @@ module.exports = ConversionManager =
compressedUpdates = compressedUpdates.concat ConcatManager.concatTwoUpdates lastCompressedUpdate, rawUpdate
ConversionManager.removeLatestCompressedUpdate doc_id, (error) ->
return callback(error) if error?
callback null, compressUpdates
callback null, compressedUpdates
else
callback null, rawUpdates
@ -54,9 +53,18 @@ module.exports = ConversionManager =
return callback(error) if error?
ConversionManager.trimLastRawUpdate doc_id, tailVersion, (error) ->
return callback(error) if error?
console.log "Pushed op", tailVersion
console.log doc_id, "Pushed op", tailVersion
callback null, true
else
console.log "Up to date"
console.log doc_id, "Up to date"
callback null, false
convertAllOldRawUpdates: (doc_id, callback = (error) ->) ->
ConversionManager.convertOldestRawUpdate doc_id, (error, converted) ->
return callback(error) if error?
if converted
# Keep going
ConversionManager.convertAllOldRawUpdates doc_id, callback
else
callback()

View file

@ -1,28 +1,32 @@
{db, ObjectId} = require "./app/coffee/mongojs"
ConversionManager = require "./app/coffee/ConversionManager"
async = require "async"
doc_id = process.argv.pop()
console.log "DOC ID", doc_id
done = () ->
console.log "DONE! Here's the history:"
db.docHistory.find { doc_id: ObjectId(doc_id) }, (error, docs) ->
db.docOps.find { }, { doc_id: true }, (error, docs) ->
throw error if error?
jobs = []
for doc in docs
do (doc) ->
jobs.push (callback) ->
doc_id = doc.doc_id.toString()
ConversionManager.convertAllOldRawUpdates doc_id, (error) ->
return callback(error) if error?
console.log doc_id, "DONE"
db.docHistory.find { doc_id: ObjectId(doc_id) }, (error, docs) ->
return callback(error) if error?
doc = docs[0]
if doc?
for update in doc.docOps
op = update.op[0]
if op.i?
console.log update.meta.start_ts, update.meta.end_ts, update.meta.user_id, "INSERT", op.p, op.i
console.log doc_id, update.meta.start_ts, update.meta.end_ts, update.meta.user_id, "INSERT", op.p, op.i
else if op.d?
console.log update.meta.start_ts, update.meta.end_ts, update.meta.user_id, "DELETE", op.p, op.d
console.log doc_id, update.meta.start_ts, update.meta.end_ts, update.meta.user_id, "DELETE", op.p, op.d
else
console.log doc_id, "NO HISTORY"
callback()
async.series jobs, (error) ->
throw error if error?
process.exit()
do next = () ->
ConversionManager.convertOldestRawUpdate doc_id, (error, converted) ->
throw error if error?
if converted
next()
else
done()

View file

@ -2,6 +2,7 @@
"name": "history-sharelatex",
"version": "0.0.1",
"dependencies": {
"async": "",
"chai": "",
"sandboxed-module": "",
"sinon": "",