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

add docHistoryStats collection to keep track of updates to docs

Brian Gough 11 лет назад
Родитель
Сommit
5c4afd5303

+ 11 - 1
services/track-changes/app/coffee/MongoManager.coffee

@@ -34,7 +34,14 @@ module.exports = MongoManager =
 		for update in updates
 			do (update) ->
 				jobs.push (callback) -> MongoManager.insertCompressedUpdate project_id, doc_id, update, temporary, callback
-		async.series jobs, callback
+		async.series jobs, (err, results) ->
+			if not temporary
+				# keep track of updates to be packed
+				db.docHistoryStats.update {doc_id:ObjectId(doc_id)}, {$inc:{updates:updates.length}}, {upsert:true}, () ->
+					callback(err,results)
+			else
+				callback(err,results)
+
 
 	insertCompressedUpdate: (project_id, doc_id, update, temporary, callback = (error) ->) ->
 		update = {
@@ -113,3 +120,6 @@ module.exports = MongoManager =
 		db.projectHistoryMetaData.ensureIndex { project_id: 1 }, { background: true }
 		# TTL index for auto deleting week old temporary ops
 		db.docHistory.ensureIndex { expiresAt: 1 }, { expireAfterSeconds: 0, background: true }
+		# For finding documents which need packing
+		db.docHistoryStats.ensureIndex { doc_id: 1 }, { background: true }
+		db.docHistoryStats.ensureIndex { updates: -1, doc_id: 1 }, { background: true }

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

@@ -1,6 +1,6 @@
 Settings = require "settings-sharelatex"
 mongojs = require "mongojs"
-db = mongojs.connect(Settings.mongo.url, ["docHistory", "projectHistoryMetaData"])
+db = mongojs.connect(Settings.mongo.url, ["docHistory", "projectHistoryMetaData", "docHistoryStats"])
 module.exports =
 	db: db
 	ObjectId: mongojs.ObjectId