Просмотр исходного кода

Store project_id alongside each change

James Allen 12 лет назад
Родитель
Сommit
962fc18329

+ 1 - 1
services/track-changes/app/coffee/DiffManager.coffee

@@ -5,7 +5,7 @@ logger = require "logger-sharelatex"
 
 module.exports = DiffManager =
 	getLatestDocAndUpdates: (project_id, doc_id, fromVersion, toVersion, callback = (error, content, version, updates) ->) ->
-		UpdatesManager.getUpdatesWithUserInfo doc_id, from: fromVersion, to: toVersion, (error, updates) ->
+		UpdatesManager.getUpdatesWithUserInfo project_id, doc_id, from: fromVersion, to: toVersion, (error, updates) ->
 			return callback(error) if error?
 			DocumentUpdaterManager.getDocument project_id, doc_id, (error, content, version) ->
 				return callback(error) if error?

+ 3 - 2
services/track-changes/app/coffee/HttpController.coffee

@@ -6,8 +6,9 @@ logger = require "logger-sharelatex"
 module.exports = HttpController =
 	flushUpdatesWithLock: (req, res, next = (error) ->) ->
 		doc_id = req.params.doc_id
+		project_id = req.params.project_id
 		logger.log doc_id: doc_id, "compressing doc history"
-		UpdatesManager.processUncompressedUpdatesWithLock doc_id, (error) ->
+		UpdatesManager.processUncompressedUpdatesWithLock project_id, doc_id, (error) ->
 			return next(error) if error?
 			res.send 204
 
@@ -38,7 +39,7 @@ module.exports = HttpController =
 		if req.query.limit?
 			limit = parseInt(req.query.limit, 10)
 
-		UpdatesManager.getSummarizedUpdates doc_id, to: to, limit: limit, (error, updates) ->
+		UpdatesManager.getSummarizedUpdates project_id, doc_id, to: to, limit: limit, (error, updates) ->
 			return next(error) if error?
 			res.send JSON.stringify updates: updates
 

+ 4 - 3
services/track-changes/app/coffee/MongoManager.coffee

@@ -24,16 +24,17 @@ module.exports = MongoManager =
 			else
 				callback null, null
 
-	insertCompressedUpdates: (doc_id, updates, callback = (error) ->) ->
+	insertCompressedUpdates: (project_id, doc_id, updates, callback = (error) ->) ->
 		jobs = []
 		for update in updates
 			do (update) ->
-				jobs.push (callback) -> MongoManager.insertCompressedUpdate doc_id, update, callback
+				jobs.push (callback) -> MongoManager.insertCompressedUpdate project_id, doc_id, update, callback
 		async.series jobs, callback
 
-	insertCompressedUpdate: (doc_id, update, callback = (error) ->) ->
+	insertCompressedUpdate: (project_id, doc_id, update, callback = (error) ->) ->
 		db.docHistory.insert {
 			doc_id: ObjectId(doc_id.toString())
+			project_id: ObjectId(project_id.toString())
 			op:     update.op
 			meta:   update.meta
 			v:      update.v

+ 21 - 24
services/track-changes/app/coffee/UpdatesManager.coffee

@@ -7,7 +7,7 @@ logger = require "logger-sharelatex"
 async = require "async"
 
 module.exports = UpdatesManager =
-	compressAndSaveRawUpdates: (doc_id, rawUpdates, callback = (error) ->) ->
+	compressAndSaveRawUpdates: (project_id, doc_id, rawUpdates, callback = (error) ->) ->
 		length = rawUpdates.length
 		if length == 0
 			return callback()
@@ -23,65 +23,65 @@ module.exports = UpdatesManager =
 
 				if rawUpdates[0]? and rawUpdates[0].v != lastCompressedUpdate.v + 1
 					error = new Error("Tried to apply raw op at version #{rawUpdates[0].v} to last compressed update with version #{lastCompressedUpdate.v}")
-					logger.error err: error, doc_id: doc_id, "inconsistent doc versions"
+					logger.error err: error, doc_id: doc_id, project_id: project_id, "inconsistent doc versions"
 					# Push the update back into Mongo - catching errors at this
 					# point is useless, we're already bailing
-					MongoManager.insertCompressedUpdates doc_id, [lastCompressedUpdate], () ->
+					MongoManager.insertCompressedUpdates project_id, doc_id, [lastCompressedUpdate], () ->
 						return callback error
 					return
 
 			compressedUpdates = UpdateCompressor.compressRawUpdates lastCompressedUpdate, rawUpdates
-			MongoManager.insertCompressedUpdates doc_id, compressedUpdates, (error) ->
+			MongoManager.insertCompressedUpdates project_id, doc_id, compressedUpdates, (error) ->
 				return callback(error) if error?
-				logger.log doc_id: doc_id, rawUpdatesLength: length, compressedUpdatesLength: compressedUpdates.length, "compressed doc updates"
+				logger.log project_id: project_id, doc_id: doc_id, rawUpdatesLength: length, compressedUpdatesLength: compressedUpdates.length, "compressed doc updates"
 				callback()
 
 	REDIS_READ_BATCH_SIZE: 100
-	processUncompressedUpdates: (doc_id, callback = (error) ->) ->
+	processUncompressedUpdates: (project_id, doc_id, callback = (error) ->) ->
 		RedisManager.getOldestRawUpdates doc_id, UpdatesManager.REDIS_READ_BATCH_SIZE, (error, rawUpdates) ->
 			return callback(error) if error?
 			length = rawUpdates.length
-			UpdatesManager.compressAndSaveRawUpdates doc_id, rawUpdates, (error) ->
+			UpdatesManager.compressAndSaveRawUpdates project_id, doc_id, rawUpdates, (error) ->
 				return callback(error) if error?
-				logger.log doc_id: doc_id, "compressed and saved doc updates"
+				logger.log project_id: project_id, doc_id: doc_id, "compressed and saved doc updates"
 				RedisManager.deleteOldestRawUpdates doc_id, length, (error) ->
 					return callback(error) if error?
 					if length == UpdatesManager.REDIS_READ_BATCH_SIZE
 						# There might be more updates
-						logger.log doc_id: doc_id, "continuing processing updates"
+						logger.log project_id: project_id, doc_id: doc_id, "continuing processing updates"
 						setTimeout () ->
-							UpdatesManager.processUncompressedUpdates doc_id, callback
+							UpdatesManager.processUncompressedUpdates project_id, doc_id, callback
 						, 0
 					else
-						logger.log doc_id: doc_id, "all raw updates processed"
+						logger.log project_id: project_id, doc_id: doc_id, "all raw updates processed"
 						callback()
 
-	processUncompressedUpdatesWithLock: (doc_id, callback = (error) ->) ->
+	processUncompressedUpdatesWithLock: (project_id, doc_id, callback = (error) ->) ->
 		LockManager.runWithLock(
 			"HistoryLock:#{doc_id}",
 			(releaseLock) ->
-				UpdatesManager.processUncompressedUpdates doc_id, releaseLock
+				UpdatesManager.processUncompressedUpdates project_id, doc_id, releaseLock
 			callback
 		)
 
-	getUpdates: (doc_id, options = {}, callback = (error, updates) ->) ->
-		UpdatesManager.processUncompressedUpdatesWithLock doc_id, (error) ->
+	getUpdates: (project_id, doc_id, options = {}, callback = (error, updates) ->) ->
+		UpdatesManager.processUncompressedUpdatesWithLock project_id, doc_id, (error) ->
 			return callback(error) if error?
 			MongoManager.getUpdates doc_id, options, callback
 
-	getUpdatesWithUserInfo: (doc_id, options = {}, callback = (error, updates) ->) ->
-		UpdatesManager.getUpdates doc_id, options, (error, updates) ->
+	getUpdatesWithUserInfo: (project_id, doc_id, options = {}, callback = (error, updates) ->) ->
+		UpdatesManager.getUpdates project_id, doc_id, options, (error, updates) ->
 			return callback(error) if error?
 			UpdatesManager.fillUserInfo updates, (error, updates) ->
 				return callback(error) if error?
 				callback null, updates
 
-	getSummarizedUpdates: (doc_id, options = {}, callback = (error, updates) ->) ->
+	getSummarizedUpdates: (project_id, doc_id, options = {}, callback = (error, updates) ->) ->
 		options.limit ||= 25
 		summarizedUpdates = []
 		to = options.to
 		do fetchNextBatch = () ->
-			UpdatesManager._extendBatchOfSummarizedUpdates doc_id, summarizedUpdates, to, options.limit, (error, updates, endOfDatabase) ->
+			UpdatesManager._extendBatchOfSummarizedUpdates project_id, doc_id, summarizedUpdates, to, options.limit, (error, updates, endOfDatabase) ->
 				return callback(error) if error?
 				if endOfDatabase or updates.length >= options.limit
 					callback null, updates
@@ -91,12 +91,13 @@ module.exports = UpdatesManager =
 					fetchNextBatch()
 
 	_extendBatchOfSummarizedUpdates: (
+		project_id, 
 		doc_id,
 		existingSummarizedUpdates,
 		to, desiredLength,
 		callback = (error, summarizedUpdates, endOfDatabase) ->
 	) ->
-		UpdatesManager.getUpdatesWithUserInfo doc_id, { to: to, limit: 3 * desiredLength }, (error, updates) ->
+		UpdatesManager.getUpdatesWithUserInfo project_id, doc_id, { to: to, limit: 3 * desiredLength }, (error, updates) ->
 			return callback(error) if error?
 			if !updates? or updates.length == 0
 				endOfDatabase = true
@@ -105,7 +106,6 @@ module.exports = UpdatesManager =
 			summarizedUpdates = UpdatesManager._summarizeUpdates(
 				updates, existingSummarizedUpdates
 			)
-			console.log "Summarized", summarizedUpdates
 			callback null,
 				summarizedUpdates.slice(0, desiredLength),
 				endOfDatabase
@@ -146,9 +146,7 @@ module.exports = UpdatesManager =
 		summarizedUpdates = existingSummarizedUpdates.slice()
 		for update in updates
 			earliestUpdate = summarizedUpdates[summarizedUpdates.length - 1]
-			console.log "Considering update", update, earliestUpdate
 			if earliestUpdate and earliestUpdate.meta.start_ts - update.meta.end_ts < @TIME_BETWEEN_DISTINCT_UPDATES
-				console.log "Concatting"
 				if update.meta.user?
 					userExists = false
 					for user in earliestUpdate.meta.users
@@ -161,7 +159,6 @@ module.exports = UpdatesManager =
 				earliestUpdate.meta.end_ts   = Math.max(earliestUpdate.meta.end_ts, update.meta.end_ts)
 				earliestUpdate.fromV = update.v
 			else
-				console.log "creating new"
 				newUpdate =
 					meta:
 						users: []

+ 6 - 0
services/track-changes/test/acceptance/coffee/AppendingUpdatesTests.coffee

@@ -42,6 +42,12 @@ describe "Appending doc ops to the history", ->
 		it "should insert the correct version number into mongo", ->
 			expect(@updates[0].v).to.equal 5
 
+		it "should store the doc id", ->
+			expect(@updates[0].doc_id.toString()).to.equal @doc_id
+
+		it "should store the project id", ->
+			expect(@updates[0].project_id.toString()).to.equal @project_id
+
 	describe "when the history has already been started", ->
 		beforeEach (done) ->
 			@project_id = ObjectId().toString()

+ 2 - 2
services/track-changes/test/unit/coffee/DiffManager/DiffManagerTests.coffee

@@ -25,7 +25,7 @@ describe "DiffManager", ->
 			@updates = [ "mock-update-1", "mock-update-2" ]
 
 			@DocumentUpdaterManager.getDocument = sinon.stub().callsArgWith(2, null, @content, @version)
-			@UpdatesManager.getUpdatesWithUserInfo = sinon.stub().callsArgWith(2, null, @updates)
+			@UpdatesManager.getUpdatesWithUserInfo = sinon.stub().callsArgWith(3, null, @updates)
 			@DiffManager.getLatestDocAndUpdates @project_id, @doc_id, @from, @to, @callback
 
 		it "should get the latest version of the doc", ->
@@ -35,7 +35,7 @@ describe "DiffManager", ->
 
 		it "should get the latest updates", ->
 			@UpdatesManager.getUpdatesWithUserInfo
-				.calledWith(@doc_id, from: @from, to: @to)
+				.calledWith(@project_id, @doc_id, from: @from, to: @to)
 				.should.equal true
 
 		it "should call the callback with the content, version and updates", ->

+ 5 - 4
services/track-changes/test/unit/coffee/HttpController/HttpControllerTests.coffee

@@ -23,14 +23,15 @@ describe "HttpController", ->
 			@req =
 				params:
 					doc_id: @doc_id
+					project_id: @project_id
 			@res =
 				send: sinon.stub()
-			@UpdatesManager.processUncompressedUpdatesWithLock = sinon.stub().callsArg(1)
+			@UpdatesManager.processUncompressedUpdatesWithLock = sinon.stub().callsArg(2)
 			@HttpController.flushUpdatesWithLock @req, @res, @next
 
 		it "should process the updates", ->
 			@UpdatesManager.processUncompressedUpdatesWithLock
-				.calledWith(@doc_id)
+				.calledWith(@project_id, @doc_id)
 				.should.equal true
 
 		it "should return a success code", ->
@@ -75,12 +76,12 @@ describe "HttpController", ->
 			@res =
 				send: sinon.stub()
 			@updates = ["mock-summarized-updates"]
-			@UpdatesManager.getSummarizedUpdates = sinon.stub().callsArgWith(2, null, @updates)
+			@UpdatesManager.getSummarizedUpdates = sinon.stub().callsArgWith(3, null, @updates)
 			@HttpController.getUpdates @req, @res, @next
 
 		it "should get the updates", ->
 			@UpdatesManager.getSummarizedUpdates
-				.calledWith(@doc_id, to: @to, limit: @limit)
+				.calledWith(@project_id, @doc_id, to: @to, limit: @limit)
 				.should.equal true
 
 		it "should return the formatted updates", ->

+ 6 - 4
services/track-changes/test/unit/coffee/MongoManager/MongoManagerTests.coffee

@@ -12,6 +12,7 @@ describe "MongoManager", ->
 			"./mongojs" : { db: @db = {}, ObjectId: ObjectId }
 		@callback = sinon.stub()
 		@doc_id = ObjectId().toString()
+		@project_id = ObjectId().toString()
 
 	describe "getLastCompressedUpdate", ->
 		beforeEach ->
@@ -100,11 +101,12 @@ describe "MongoManager", ->
 			@update = { op: "op", meta: "meta", v: "v"}
 			@db.docHistory =
 				insert: sinon.stub().callsArg(1)
-			@MongoManager.insertCompressedUpdate @doc_id, @update, @callback
+			@MongoManager.insertCompressedUpdate @project_id, @doc_id, @update, @callback
 
 		it "should insert the update", ->
 			@db.docHistory.insert
 				.calledWith({
+					project_id: ObjectId(@project_id),
 					doc_id: ObjectId(@doc_id),
 					op: @update.op,
 					meta: @update.meta,
@@ -118,15 +120,15 @@ describe "MongoManager", ->
 	describe "insertCompressedUpdates", ->
 		beforeEach (done) ->
 			@updates = [ "mock-update-1", "mock-update-2" ]
-			@MongoManager.insertCompressedUpdate = sinon.stub().callsArg(2)
-			@MongoManager.insertCompressedUpdates @doc_id, @updates, (args...) =>
+			@MongoManager.insertCompressedUpdate = sinon.stub().callsArg(3)
+			@MongoManager.insertCompressedUpdates @project_id, @doc_id, @updates, (args...) =>
 				@callback(args...)
 				done()
 
 		it "should insert each update", ->
 			for update in @updates
 				@MongoManager.insertCompressedUpdate
-					.calledWith(@doc_id, update)
+					.calledWith(@project_id, @doc_id, update)
 					.should.equal true
 
 		it "should call the callback", ->

+ 41 - 40
services/track-changes/test/unit/coffee/UpdatesManager/UpdatesManagerTests.coffee

@@ -15,6 +15,7 @@ describe "UpdatesManager", ->
 			"./WebApiManager": @WebApiManager = {}
 			"logger-sharelatex": { log: sinon.stub(), error: sinon.stub() }
 		@doc_id = "doc-id-123"
+		@project_id = "project-id-123"
 		@callback = sinon.stub()
 
 	describe "compressAndSaveRawUpdates", ->
@@ -22,7 +23,7 @@ describe "UpdatesManager", ->
 			beforeEach ->
 				@MongoManager.popLastCompressedUpdate = sinon.stub()
 				@MongoManager.insertCompressedUpdates = sinon.stub()
-				@UpdatesManager.compressAndSaveRawUpdates @doc_id, [], @callback
+				@UpdatesManager.compressAndSaveRawUpdates @project_id, @doc_id, [], @callback
 
 			it "should not need to access the database", ->
 				@MongoManager.popLastCompressedUpdate.called.should.equal false
@@ -37,9 +38,9 @@ describe "UpdatesManager", ->
 				@compressedUpdates = { v: 13, op: "compressed-op-12" }
 
 				@MongoManager.popLastCompressedUpdate = sinon.stub().callsArgWith(1, null, null)
-				@MongoManager.insertCompressedUpdates = sinon.stub().callsArg(2)
+				@MongoManager.insertCompressedUpdates = sinon.stub().callsArg(3)
 				@UpdateCompressor.compressRawUpdates = sinon.stub().returns(@compressedUpdates)
-				@UpdatesManager.compressAndSaveRawUpdates @doc_id, @rawUpdates, @callback
+				@UpdatesManager.compressAndSaveRawUpdates @project_id, @doc_id, @rawUpdates, @callback
 
 			it "should try to pop the last compressed op", ->
 				@MongoManager.popLastCompressedUpdate
@@ -53,7 +54,7 @@ describe "UpdatesManager", ->
 			
 			it "should save the compressed ops", ->
 				@MongoManager.insertCompressedUpdates
-					.calledWith(@doc_id, @compressedUpdates)
+					.calledWith(@project_id, @doc_id, @compressedUpdates)
 					.should.equal true
 
 			it "should call the callback", ->
@@ -65,13 +66,13 @@ describe "UpdatesManager", ->
 				@compressedUpdates = { v: 13, op: "compressed-op-12" }
 
 				@MongoManager.popLastCompressedUpdate = sinon.stub().callsArgWith(1, null, @lastCompressedUpdate)
-				@MongoManager.insertCompressedUpdates = sinon.stub().callsArg(2)
+				@MongoManager.insertCompressedUpdates = sinon.stub().callsArg(3)
 				@UpdateCompressor.compressRawUpdates = sinon.stub().returns(@compressedUpdates)
 
 			describe "when the raw ops start where the existing history ends", ->
 				beforeEach ->
 					@rawUpdates = [{ v: 12, op: "mock-op-12" }, { v: 13, op: "mock-op-13" }]
-					@UpdatesManager.compressAndSaveRawUpdates @doc_id, @rawUpdates, @callback
+					@UpdatesManager.compressAndSaveRawUpdates @project_id, @doc_id, @rawUpdates, @callback
 
 				it "should try to pop the last compressed op", ->
 					@MongoManager.popLastCompressedUpdate
@@ -85,7 +86,7 @@ describe "UpdatesManager", ->
 				
 				it "should save the compressed ops", ->
 					@MongoManager.insertCompressedUpdates
-						.calledWith(@doc_id, @compressedUpdates)
+						.calledWith(@project_id, @doc_id, @compressedUpdates)
 						.should.equal true
 
 				it "should call the callback", ->
@@ -95,7 +96,7 @@ describe "UpdatesManager", ->
 				beforeEach ->
 					@rawUpdates = [{ v: 10, op: "mock-op-10" }, { v: 11, op: "mock-op-11"}, { v: 12, op: "mock-op-12" }, { v: 13, op: "mock-op-13" }]
 
-					@UpdatesManager.compressAndSaveRawUpdates @doc_id, @rawUpdates, @callback
+					@UpdatesManager.compressAndSaveRawUpdates @project_id, @doc_id, @rawUpdates, @callback
 
 				it "should only compress the more recent raw ops", ->
 					@UpdateCompressor.compressRawUpdates
@@ -105,7 +106,7 @@ describe "UpdatesManager", ->
 			describe "when the raw ops do not follow from the last compressed op version", ->
 				beforeEach ->
 					@rawUpdates = [{ v: 13, op: "mock-op-13" }]
-					@UpdatesManager.compressAndSaveRawUpdates @doc_id, @rawUpdates, @callback
+					@UpdatesManager.compressAndSaveRawUpdates @project_id, @doc_id, @rawUpdates, @callback
 
 				it "should call the callback with an error", ->
 					@callback
@@ -115,7 +116,7 @@ describe "UpdatesManager", ->
 				it "should put the popped update back into mongo", ->
 					@MongoManager.insertCompressedUpdates.calledOnce.should.equal true
 					@MongoManager.insertCompressedUpdates
-						.calledWith(@doc_id, [@lastCompressedUpdate])
+						.calledWith(@project_id, @doc_id, [@lastCompressedUpdate])
 						.should.equal true
 
 	describe "processUncompressedUpdates", ->
@@ -123,9 +124,9 @@ describe "UpdatesManager", ->
 			beforeEach ->
 				@updates = ["mock-update"]
 				@RedisManager.getOldestRawUpdates = sinon.stub().callsArgWith(2, null, @updates)
-				@UpdatesManager.compressAndSaveRawUpdates = sinon.stub().callsArgWith(2)
+				@UpdatesManager.compressAndSaveRawUpdates = sinon.stub().callsArgWith(3)
 				@RedisManager.deleteOldestRawUpdates = sinon.stub().callsArg(2)
-				@UpdatesManager.processUncompressedUpdates @doc_id, @callback
+				@UpdatesManager.processUncompressedUpdates @project_id, @doc_id, @callback
 
 			it "should get the oldest updates", ->
 				@RedisManager.getOldestRawUpdates
@@ -134,7 +135,7 @@ describe "UpdatesManager", ->
 
 			it "should compress and save the updates", ->
 				@UpdatesManager.compressAndSaveRawUpdates
-					.calledWith(@doc_id, @updates)
+					.calledWith(@project_id, @doc_id, @updates)
 					.should.equal true
 
 			it "should delete the batch of uncompressed updates that was just processed", ->
@@ -155,9 +156,9 @@ describe "UpdatesManager", ->
 					@redisArray = @redisArray.slice(batchSize)
 					callback null, updates
 				sinon.spy @RedisManager, "getOldestRawUpdates"
-				@UpdatesManager.compressAndSaveRawUpdates = sinon.stub().callsArgWith(2)
+				@UpdatesManager.compressAndSaveRawUpdates = sinon.stub().callsArgWith(3)
 				@RedisManager.deleteOldestRawUpdates = sinon.stub().callsArg(2)
-				@UpdatesManager.processUncompressedUpdates @doc_id, (args...) =>
+				@UpdatesManager.processUncompressedUpdates @project_id, @doc_id, (args...) =>
 					@callback(args...)
 					done()
 
@@ -166,13 +167,13 @@ describe "UpdatesManager", ->
 
 			it "should compress and save the updates in batches", ->
 				@UpdatesManager.compressAndSaveRawUpdates
-					.calledWith(@doc_id, @updates.slice(0,2))
+					.calledWith(@project_id, @doc_id, @updates.slice(0,2))
 					.should.equal true
 				@UpdatesManager.compressAndSaveRawUpdates
-					.calledWith(@doc_id, @updates.slice(2,4))
+					.calledWith(@project_id, @doc_id, @updates.slice(2,4))
 					.should.equal true
 				@UpdatesManager.compressAndSaveRawUpdates
-					.calledWith(@doc_id, @updates.slice(4,5))
+					.calledWith(@project_id, @doc_id, @updates.slice(4,5))
 					.should.equal true
 
 			it "should delete the batches of uncompressed updates", ->
@@ -185,7 +186,7 @@ describe "UpdatesManager", ->
 		beforeEach ->
 			@UpdatesManager.processUncompressedUpdates = sinon.stub().callsArg(2)
 			@LockManager.runWithLock = sinon.stub().callsArg(2)
-			@UpdatesManager.processUncompressedUpdatesWithLock @doc_id, @callback
+			@UpdatesManager.processUncompressedUpdatesWithLock @project_id, @doc_id, @callback
 
 		it "should run processUncompressedUpdates with the lock", ->
 			@LockManager.runWithLock
@@ -202,12 +203,12 @@ describe "UpdatesManager", ->
 			@updates = ["mock-updates"]
 			@options = { to: "mock-to", limit: "mock-limit" }
 			@MongoManager.getUpdates = sinon.stub().callsArgWith(2, null, @updates)
-			@UpdatesManager.processUncompressedUpdatesWithLock = sinon.stub().callsArg(1)
-			@UpdatesManager.getUpdates @doc_id, @options, @callback
+			@UpdatesManager.processUncompressedUpdatesWithLock = sinon.stub().callsArg(2)
+			@UpdatesManager.getUpdates @project_id, @doc_id, @options, @callback
 
 		it "should process outstanding updates", ->
 			@UpdatesManager.processUncompressedUpdatesWithLock
-				.calledWith(@doc_id)
+				.calledWith(@project_id, @doc_id)
 				.should.equal true
 
 		it "should get the updates from the database", ->
@@ -225,13 +226,13 @@ describe "UpdatesManager", ->
 			@updates = ["mock-updates"]
 			@options = { to: "mock-to", limit: "mock-limit" }
 			@updatesWithUserInfo = ["updates-with-user-info"]
-			@UpdatesManager.getUpdates = sinon.stub().callsArgWith(2, null, @updates)
+			@UpdatesManager.getUpdates = sinon.stub().callsArgWith(3, null, @updates)
 			@UpdatesManager.fillUserInfo = sinon.stub().callsArgWith(1, null, @updatesWithUserInfo)
-			@UpdatesManager.getUpdatesWithUserInfo @doc_id, @options, @callback
+			@UpdatesManager.getUpdatesWithUserInfo @project_id, @doc_id, @options, @callback
 
 		it "should get the updates", ->
 			@UpdatesManager.getUpdates
-				.calledWith(@doc_id, @options)
+				.calledWith(@project_id, @doc_id, @options)
 				.should.equal true
 
 		it "should file the updates with the user info", ->
@@ -255,12 +256,12 @@ describe "UpdatesManager", ->
 				@existingSummarizedUpdates = ["summarized-updates-3"]
 				@summarizedUpdates = ["summarized-updates-3", "summarized-update-2", "summarized-update-1"]
 				@UpdatesManager._summarizeUpdates = sinon.stub().returns(@summarizedUpdates)
-				@UpdatesManager.getUpdatesWithUserInfo = sinon.stub().callsArgWith(2, null, @updates)
-				@UpdatesManager._extendBatchOfSummarizedUpdates @doc_id, @existingSummarizedUpdates, @to, @limit, @callback
+				@UpdatesManager.getUpdatesWithUserInfo = sinon.stub().callsArgWith(3, null, @updates)
+				@UpdatesManager._extendBatchOfSummarizedUpdates @project_id, @doc_id, @existingSummarizedUpdates, @to, @limit, @callback
 
 			it "should get the updates", ->
 				@UpdatesManager.getUpdatesWithUserInfo
-					.calledWith(@doc_id, { to: @to, limit: 3 * @limit })
+					.calledWith(@project_id, @doc_id, { to: @to, limit: 3 * @limit })
 					.should.equal true
 
 			it "should summarize the updates", ->
@@ -275,8 +276,8 @@ describe "UpdatesManager", ->
 			beforeEach ->
 				@updates = []
 				@UpdatesManager._summarizeUpdates = sinon.stub().returns(@summarizedUpdates)
-				@UpdatesManager.getUpdatesWithUserInfo = sinon.stub().callsArgWith(2, null, @updates)
-				@UpdatesManager._extendBatchOfSummarizedUpdates @doc_id, @existingSummarizedUpdates, @to, @limit, @callback
+				@UpdatesManager.getUpdatesWithUserInfo = sinon.stub().callsArgWith(3, null, @updates)
+				@UpdatesManager._extendBatchOfSummarizedUpdates @project_id, @doc_id, @existingSummarizedUpdates, @to, @limit, @callback
 
 			it "should call the callback with the summarized updates and true for end-of-database", ->
 				@callback.calledWith(null, @summarizedUpdates.slice(0, @limit), true).should.equal true
@@ -287,12 +288,12 @@ describe "UpdatesManager", ->
 				@to = 42
 				@limit = 2
 				@updates = ["summarized-updates-3", "summarized-updates-2"]
-				@UpdatesManager._extendBatchOfSummarizedUpdates = sinon.stub().callsArgWith(4, null, @updates)
-				@UpdatesManager.getSummarizedUpdates @doc_id, { to: @to, limit: @limit }, @callback
+				@UpdatesManager._extendBatchOfSummarizedUpdates = sinon.stub().callsArgWith(5, null, @updates)
+				@UpdatesManager.getSummarizedUpdates @project_id, @doc_id, { to: @to, limit: @limit }, @callback
 
 			it "should get the batch of summarized updates", ->
 				@UpdatesManager._extendBatchOfSummarizedUpdates
-					.calledWith(@doc_id, [], @to, @limit)
+					.calledWith(@project_id, @doc_id, [], @to, @limit)
 					.should.equal true
 
 			it "should call the callback with the updates", ->
@@ -304,22 +305,22 @@ describe "UpdatesManager", ->
 				@limit = 4
 				@firstBatch =  [{ toV: 6, fromV: 6 }, { toV: 5, fromV: 5 }]
 				@secondBatch = [{ toV: 4, fromV: 4 }, { toV: 3, fromV: 3 }]
-				@UpdatesManager._extendBatchOfSummarizedUpdates = (doc_id, existingUpdates, to, limit, callback) =>
+				@UpdatesManager._extendBatchOfSummarizedUpdates = (project_id, doc_id, existingUpdates, to, limit, callback) =>
 					if existingUpdates.length == 0
 						callback null, @firstBatch, false
 					else
 						callback null, @firstBatch.concat(@secondBatch), false
 				sinon.spy @UpdatesManager, "_extendBatchOfSummarizedUpdates"
-				@UpdatesManager.getSummarizedUpdates @doc_id, { to: @to, limit: @limit }, @callback
+				@UpdatesManager.getSummarizedUpdates @project_id, @doc_id, { to: @to, limit: @limit }, @callback
 
 			it "should get the first batch of summarized updates", ->
 				@UpdatesManager._extendBatchOfSummarizedUpdates
-					.calledWith(@doc_id, [], @to, @limit)
+					.calledWith(@project_id, @doc_id, [], @to, @limit)
 					.should.equal true
 
 			it "should get the second batch of summarized updates", ->
 				@UpdatesManager._extendBatchOfSummarizedUpdates
-					.calledWith(@doc_id, @firstBatch, 4, @limit)
+					.calledWith(@project_id, @doc_id, @firstBatch, 4, @limit)
 					.should.equal true
 
 			it "should call the callback with all the updates", ->
@@ -330,12 +331,12 @@ describe "UpdatesManager", ->
 				@to = 6
 				@limit = 4
 				@updates =  [{ toV: 6, fromV: 6 }, { toV: 5, fromV: 5 }]
-				@UpdatesManager._extendBatchOfSummarizedUpdates = sinon.stub().callsArgWith(4, null, @updates, true)
-				@UpdatesManager.getSummarizedUpdates @doc_id, { to: @to, limit: @limit }, @callback
+				@UpdatesManager._extendBatchOfSummarizedUpdates = sinon.stub().callsArgWith(5, null, @updates, true)
+				@UpdatesManager.getSummarizedUpdates @project_id, @doc_id, { to: @to, limit: @limit }, @callback
 
 			it "should get the batch of summarized updates", ->
 				@UpdatesManager._extendBatchOfSummarizedUpdates
-					.calledWith(@doc_id, [], @to, @limit)
+					.calledWith(@project_id, @doc_id, [], @to, @limit)
 					.should.equal true
 
 			it "should call the callback with the updates", ->