mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Create method for pushing uncompressed ops into redis
This commit is contained in:
parent
86e42ce1de
commit
6f19f46d96
4 changed files with 41 additions and 0 deletions
|
@ -44,6 +44,7 @@ module.exports = DocOpsManager =
|
|||
callback null, ops
|
||||
|
||||
pushDocOp: (project_id, doc_id, op, callback = (error) ->) ->
|
||||
console.log "PUSHING OP", op
|
||||
RedisManager.pushDocOp doc_id, op, callback
|
||||
|
||||
_ensureOpsAreLoaded: (project_id, doc_id, backToVersion, callback = (error) ->) ->
|
||||
|
|
|
@ -8,12 +8,14 @@ DOCLINES = "doclines"
|
|||
DOCOPS = "DocOps"
|
||||
DOCVERSION = "DocVersion"
|
||||
DOCIDSWITHPENDINGUPDATES = "DocsWithPendingUpdates"
|
||||
UNCOMPRESSED_HISTORY_OPS = "UncompressedHistoryOps"
|
||||
|
||||
module.exports =
|
||||
|
||||
allDocs : ALLDOCSKEY
|
||||
docLines : (op)-> DOCLINES+":"+op.doc_id
|
||||
docOps : (op)-> DOCOPS+":"+op.doc_id
|
||||
uncompressedHistoryOp: (op) -> UNCOMPRESSED_HISTORY_OPS + ":" + op.doc_id
|
||||
docVersion : (op)-> DOCVERSION+":"+op.doc_id
|
||||
projectKey : (op)-> PROJECTKEY+":"+op.doc_id
|
||||
blockingKey : (op)-> BLOCKINGKEY+":"+op.doc_id
|
||||
|
|
|
@ -155,6 +155,10 @@ module.exports =
|
|||
jsonOps = ops.map (op) -> JSON.stringify op
|
||||
rclient.lpush keys.docOps(doc_id: doc_id), jsonOps.reverse(), callback
|
||||
|
||||
pushUncompressedHistoryOp: (doc_id, op, callback = (error) ->) ->
|
||||
jsonOp = JSON.stringify op
|
||||
rclient.rpush keys.uncompressedHistoryOp(doc_id: doc_id), jsonOp, callback
|
||||
|
||||
getDocOpsLength: (doc_id, callback = (error, length) ->) ->
|
||||
rclient.llen keys.docOps(doc_id: doc_id), callback
|
||||
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
sinon = require('sinon')
|
||||
chai = require('chai')
|
||||
should = chai.should()
|
||||
modulePath = "../../../../app/js/RedisManager.js"
|
||||
SandboxedModule = require('sandboxed-module')
|
||||
|
||||
describe "RedisManager.pushUncompressedHistoryOp", ->
|
||||
beforeEach ->
|
||||
@RedisManager = SandboxedModule.require modulePath, requires:
|
||||
"redis": createClient: () =>
|
||||
@rclient =
|
||||
auth: () ->
|
||||
multi: () => @rclient
|
||||
"logger-sharelatex": @logger = {log: sinon.stub()}
|
||||
@doc_id = "doc-id-123"
|
||||
@callback = sinon.stub()
|
||||
@rclient.rpush = sinon.stub()
|
||||
|
||||
describe "successfully", ->
|
||||
beforeEach ->
|
||||
@op = { op: [{ i: "foo", p: 4 }] }
|
||||
@rclient.rpush = sinon.stub().callsArg(2)
|
||||
@RedisManager.pushUncompressedHistoryOp @doc_id, @op, @callback
|
||||
|
||||
it "should push the doc op into the doc ops list", ->
|
||||
@rclient.rpush
|
||||
.calledWith("UncompressedHistoryOps:#{@doc_id}", JSON.stringify(@op))
|
||||
.should.equal true
|
||||
|
||||
it "should call the callback", ->
|
||||
@callback.called.should.equal true
|
||||
|
||||
|
||||
|
Loading…
Reference in a new issue