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) -> ConversionManager.getLastRawUpdateAndVersion doc_id, (error, rawUpdate, currentVersion, tailVersion) ->
return callback(error) if error? return callback(error) if error?
rawUpdates = ConcatManager.normalizeUpdate(rawUpdate) if currentVersion - tailVersion > ConversionManager.OPS_TO_LEAVE
rawUpdates = ConcatManager.normalizeUpdate(rawUpdate)
if currentVersion - tailVersion > ConcatManager.OPS_TO_LEAVE ConversionManager.getLatestCompressedUpdate doc_id, (error, lastCompressedUpdate) ->
ConversonManager.getLatestCompressedUpdate doc_id, (error, lastCompressedUpdate) ->
return callback(error) if error? return callback(error) if error?
removeAndModifyPreviousCompressedUpdate = (callback, compressedUpdates) -> removeAndModifyPreviousCompressedUpdate = (callback, compressedUpdates) ->
@ -44,7 +43,7 @@ module.exports = ConversionManager =
compressedUpdates = compressedUpdates.concat ConcatManager.concatTwoUpdates lastCompressedUpdate, rawUpdate compressedUpdates = compressedUpdates.concat ConcatManager.concatTwoUpdates lastCompressedUpdate, rawUpdate
ConversionManager.removeLatestCompressedUpdate doc_id, (error) -> ConversionManager.removeLatestCompressedUpdate doc_id, (error) ->
return callback(error) if error? return callback(error) if error?
callback null, compressUpdates callback null, compressedUpdates
else else
callback null, rawUpdates callback null, rawUpdates
@ -54,9 +53,18 @@ module.exports = ConversionManager =
return callback(error) if error? return callback(error) if error?
ConversionManager.trimLastRawUpdate doc_id, tailVersion, (error) -> ConversionManager.trimLastRawUpdate doc_id, tailVersion, (error) ->
return callback(error) if error? return callback(error) if error?
console.log "Pushed op", tailVersion console.log doc_id, "Pushed op", tailVersion
callback null, true callback null, true
else else
console.log "Up to date" console.log doc_id, "Up to date"
callback null, false 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" {db, ObjectId} = require "./app/coffee/mongojs"
ConversionManager = require "./app/coffee/ConversionManager" ConversionManager = require "./app/coffee/ConversionManager"
async = require "async"
doc_id = process.argv.pop() db.docOps.find { }, { doc_id: true }, (error, docs) ->
console.log "DOC ID", doc_id throw error if error?
jobs = []
done = () -> for doc in docs
console.log "DONE! Here's the history:" do (doc) ->
db.docHistory.find { doc_id: ObjectId(doc_id) }, (error, docs) -> 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 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 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? throw error if error?
doc = docs[0]
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
else if op.d?
console.log update.meta.start_ts, update.meta.end_ts, update.meta.user_id, "DELETE", op.p, op.d
process.exit() 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", "name": "history-sharelatex",
"version": "0.0.1", "version": "0.0.1",
"dependencies": { "dependencies": {
"async": "",
"chai": "", "chai": "",
"sandboxed-module": "", "sandboxed-module": "",
"sinon": "", "sinon": "",