Ver Fonte

Use expiresAt rather than tempCreatedAt

James Allen há 12 anos atrás
pai
commit
29ad81c134

+ 6 - 5
services/track-changes/app/coffee/MongoManager.coffee

@@ -40,7 +40,11 @@ module.exports = MongoManager =
 			v:      update.v
 		}
 		if temporary
-			update.tempCreatedAt = new Date()
+			seconds = 1000
+			minutes = 60 * seconds
+			hours = 60 * minutes
+			days = 24 * hours
+			update.expiresAt = new Date(Date.now() + 7 * days)
 		db.docHistory.insert update, callback
 
 	getDocUpdates:(doc_id, options = {}, callback = (error, updates) ->) ->
@@ -120,7 +124,4 @@ module.exports = MongoManager =
 		# For finding project meta-data
 		db.projectHistoryMetaData.ensureIndex { project_id: 1 }
 		# TTL index for auto deleting week old temporary ops
-		minutes = 60
-		hours = 60 * minutes
-		days = 24 * hours
-		db.docHistory.ensureIndex { tempCreatedAt: 1 }, { expireAfterSeconds: 7 * days }
+		db.docHistory.ensureIndex { tempCreatedAt: 1 }, { expireAfterSeconds: 0 }

+ 4 - 4
services/track-changes/test/acceptance/coffee/AppendingUpdatesTests.coffee

@@ -250,8 +250,8 @@ describe "Appending doc ops to the history", ->
 					throw error if error?
 					done()
 
-		it "should not add a tempCreatedAt entry in the update in mongo", ->
-			expect(@updates[0].tempCreatedAt).to.be.undefined
+		it "should not add a expiresAt entry in the update in mongo", ->
+			expect(@updates[0].expiresAt).to.be.undefined
 
 	describe "when the project does not have versioning enabled", ->
 		before (done) ->
@@ -270,5 +270,5 @@ describe "Appending doc ops to the history", ->
 					throw error if error?
 					done()
 
-		it "should add a tempCreatedAt entry in the update in mongo", ->
-			expect(@updates[0].tempCreatedAt).to.exist
+		it "should add a expiresAt entry in the update in mongo", ->
+			expect(@updates[0].expiresAt).to.exist

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

@@ -111,7 +111,7 @@ describe "MongoManager", ->
 			beforeEach ->
 				@MongoManager.insertCompressedUpdate @project_id, @doc_id, @update, true, @callback
 
-			it "should insert the update with a tempCreatedAt field", ->
+			it "should insert the update with a expiresAt field one week away", ->
 				@db.docHistory.insert
 					.calledWith({
 						project_id: ObjectId(@project_id),
@@ -119,7 +119,7 @@ describe "MongoManager", ->
 						op: @update.op,
 						meta: @update.meta,
 						v: @update.v
-						tempCreatedAt: new Date()
+						expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000)
 					})
 					.should.equal true
 
@@ -130,7 +130,7 @@ describe "MongoManager", ->
 			beforeEach ->
 				@MongoManager.insertCompressedUpdate @project_id, @doc_id, @update, false, @callback
 
-			it "should insert the update with no tempCreatedAt field", ->
+			it "should insert the update with no expiresAt field", ->
 				@db.docHistory.insert
 					.calledWith({
 						project_id: ObjectId(@project_id),