Flush all docs in a project before getting updates

This commit is contained in:
James Allen 2014-03-21 13:48:14 +00:00
parent cd9cb51027
commit 2cd85fefec
5 changed files with 60 additions and 4 deletions

View file

@ -26,3 +26,6 @@ module.exports = RedisManager =
multi.exec (error, results) ->
return callback(error) if error?
callback null
getDocIdsWithHistoryOps: (project_id, callback = (error, doc_ids) ->) ->
rclient.smembers docsWithHistoryOpsKey(project_id), callback

View file

@ -64,6 +64,16 @@ module.exports = UpdatesManager =
callback
)
processUncompressedUpdatesForProject: (project_id, callback = (error) ->) ->
RedisManager.getDocIdsWithHistoryOps project_id, (error, doc_ids) ->
return callback(error) if error?
jobs = []
for doc_id in doc_ids
do (doc_id) ->
jobs.push (callback) ->
UpdatesManager.processUncompressedUpdatesWithLock project_id, doc_id, callback
async.parallelLimit jobs, 5, callback
getDocUpdates: (project_id, doc_id, options = {}, callback = (error, updates) ->) ->
UpdatesManager.processUncompressedUpdatesWithLock project_id, doc_id, (error) ->
return callback(error) if error?
@ -77,7 +87,9 @@ module.exports = UpdatesManager =
callback null, updates
getProjectUpdates: (project_id, options = {}, callback = (error, updates) ->) ->
MongoManager.getProjectUpdates project_id, options, callback
UpdatesManager.processUncompressedUpdatesForProject project_id, (error) ->
return callback(error) if error?
MongoManager.getProjectUpdates project_id, options, callback
getProjectUpdatesWithUserInfo: (project_id, options = {}, callback = (error, updates) ->) ->
UpdatesManager.getProjectUpdates project_id, options, (error, updates) ->

View file

@ -43,9 +43,7 @@ describe "Getting updates", ->
TrackChangesClient.pushRawUpdates @project_id, @doc_id, @updates, (error) =>
throw error if error?
TrackChangesClient.flushUpdates @project_id, @doc_id, (error) =>
throw error if error?
done()
done()
after: () ->
MockWebApi.getUser.restore()

View file

@ -52,3 +52,17 @@ describe "RedisManager", ->
it "should call the callback ", ->
@callback.called.should.equal true
describe "getDocIdsWithHistoryOps", ->
beforeEach ->
@doc_ids = ["mock-id-1", "mock-id-2"]
@rclient.smembers = sinon.stub().callsArgWith(1, null, @doc_ids)
@RedisManager.getDocIdsWithHistoryOps @project_id, @callback
it "should read the doc_ids from redis", ->
@rclient.smembers
.calledWith("DocsWithHistoryOps:#{@project_id}")
.should.equal true
it "should call the callback with the doc_ids", ->
@callback.calledWith(null, @doc_ids).should.equal true

View file

@ -248,8 +248,14 @@ describe "UpdatesManager", ->
@updates = ["mock-updates"]
@options = { before: "mock-before", limit: "mock-limit" }
@MongoManager.getProjectUpdates = sinon.stub().callsArgWith(2, null, @updates)
@UpdatesManager.processUncompressedUpdatesForProject = sinon.stub().callsArg(1)
@UpdatesManager.getProjectUpdates @project_id, @options, @callback
it "should process any outstanding updates", ->
@UpdatesManager.processUncompressedUpdatesForProject
.calledWith(@project_id)
.should.equal true
it "should get the updates from the database", ->
@MongoManager.getProjectUpdates
.calledWith(@project_id, @options)
@ -260,6 +266,29 @@ describe "UpdatesManager", ->
.calledWith(null, @updates)
.should.equal true
describe "processUncompressedUpdatesForProject", ->
beforeEach (done) ->
@doc_ids = ["mock-id-1", "mock-id-2"]
@UpdatesManager.processUncompressedUpdatesWithLock = sinon.stub().callsArg(2)
@RedisManager.getDocIdsWithHistoryOps = sinon.stub().callsArgWith(1, null, @doc_ids)
@UpdatesManager.processUncompressedUpdatesForProject @project_id, () =>
@callback()
done()
it "should get all the docs with history ops", ->
@RedisManager.getDocIdsWithHistoryOps
.calledWith(@project_id)
.should.equal true
it "should process the doc ops for the each doc_id", ->
for doc_id in @doc_ids
@UpdatesManager.processUncompressedUpdatesWithLock
.calledWith(@project_id, doc_id)
.should.equal true
it "should call the callback", ->
@callback.called.should.equal true
describe "getProjectUpdatesWithUserInfo", ->
beforeEach ->
@updates = ["mock-updates"]