From 6f19f46d961d92737a7df011a751f8fbe463c6fe Mon Sep 17 00:00:00 2001 From: James Allen Date: Mon, 24 Feb 2014 16:37:45 +0000 Subject: [PATCH] Create method for pushing uncompressed ops into redis --- .../app/coffee/DocOpsManager.coffee | 1 + .../app/coffee/RedisKeyBuilder.coffee | 2 ++ .../app/coffee/RedisManager.coffee | 4 +++ .../pushUncompressedHistoryOpTests.coffee | 34 +++++++++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 services/document-updater/test/unit/coffee/RedisManager/pushUncompressedHistoryOpTests.coffee diff --git a/services/document-updater/app/coffee/DocOpsManager.coffee b/services/document-updater/app/coffee/DocOpsManager.coffee index 0e90f5b462..032f9f6566 100644 --- a/services/document-updater/app/coffee/DocOpsManager.coffee +++ b/services/document-updater/app/coffee/DocOpsManager.coffee @@ -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) ->) -> diff --git a/services/document-updater/app/coffee/RedisKeyBuilder.coffee b/services/document-updater/app/coffee/RedisKeyBuilder.coffee index a444341ea1..2bd1ed08c8 100644 --- a/services/document-updater/app/coffee/RedisKeyBuilder.coffee +++ b/services/document-updater/app/coffee/RedisKeyBuilder.coffee @@ -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 diff --git a/services/document-updater/app/coffee/RedisManager.coffee b/services/document-updater/app/coffee/RedisManager.coffee index b2c4c9c9d0..5f6c880cee 100644 --- a/services/document-updater/app/coffee/RedisManager.coffee +++ b/services/document-updater/app/coffee/RedisManager.coffee @@ -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 diff --git a/services/document-updater/test/unit/coffee/RedisManager/pushUncompressedHistoryOpTests.coffee b/services/document-updater/test/unit/coffee/RedisManager/pushUncompressedHistoryOpTests.coffee new file mode 100644 index 0000000000..3b743db6e4 --- /dev/null +++ b/services/document-updater/test/unit/coffee/RedisManager/pushUncompressedHistoryOpTests.coffee @@ -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 + + +