mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
33 lines
1.1 KiB
CoffeeScript
33 lines
1.1 KiB
CoffeeScript
|
Settings = require('settings-sharelatex')
|
||
|
rclient = require("redis-sharelatex").createClient(Settings.redis.web)
|
||
|
async = require "async"
|
||
|
|
||
|
module.exports = WebRedisManager =
|
||
|
getPendingUpdatesForDoc : (doc_id, callback)->
|
||
|
multi = rclient.multi()
|
||
|
multi.lrange "PendingUpdates:#{doc_id}", 0 , -1
|
||
|
multi.del "PendingUpdates:#{doc_id}"
|
||
|
multi.exec (error, replys) ->
|
||
|
return callback(error) if error?
|
||
|
jsonUpdates = replys[0]
|
||
|
updates = []
|
||
|
for jsonUpdate in jsonUpdates
|
||
|
try
|
||
|
update = JSON.parse jsonUpdate
|
||
|
catch e
|
||
|
return callback e
|
||
|
updates.push update
|
||
|
callback error, updates
|
||
|
|
||
|
getUpdatesLength: (doc_id, callback)->
|
||
|
rclient.llen "PendingUpdates:#{doc_id}", callback
|
||
|
|
||
|
pushUncompressedHistoryOp: (project_id, doc_id, op, callback = (error, length) ->) ->
|
||
|
jsonOp = JSON.stringify op
|
||
|
async.parallel [
|
||
|
(cb) -> rclient.rpush "UncompressedHistoryOps:#{doc_id}", jsonOp, cb
|
||
|
(cb) -> rclient.sadd "DocsWithHistoryOps:#{project_id}", doc_id, cb
|
||
|
], (error, results) ->
|
||
|
return callback(error) if error?
|
||
|
[length, _] = results
|
||
|
callback(error, length)
|