mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
27 lines
854 B
CoffeeScript
27 lines
854 B
CoffeeScript
Settings = require('settings-sharelatex')
|
|
rclient = require("redis-sharelatex").createClient(Settings.redis.realtime)
|
|
Keys = Settings.redis.realtime.key_schema
|
|
logger = require('logger-sharelatex')
|
|
|
|
module.exports = RealTimeRedisManager =
|
|
getPendingUpdatesForDoc : (doc_id, callback)->
|
|
multi = rclient.multi()
|
|
multi.lrange Keys.pendingUpdates({doc_id}), 0 , -1
|
|
multi.del Keys.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 Keys.pendingUpdates({doc_id}), callback
|
|
|
|
sendData: (data) ->
|
|
rclient.publish "applied-ops", JSON.stringify(data)
|