From 29ad81c134047286cd884145b39714a84381f4c5 Mon Sep 17 00:00:00 2001 From: James Allen Date: Fri, 16 May 2014 16:41:14 +0100 Subject: [PATCH] Use expiresAt rather than tempCreatedAt --- services/track-changes/app/coffee/MongoManager.coffee | 11 ++++++----- .../acceptance/coffee/AppendingUpdatesTests.coffee | 8 ++++---- .../unit/coffee/MongoManager/MongoManagerTests.coffee | 6 +++--- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/services/track-changes/app/coffee/MongoManager.coffee b/services/track-changes/app/coffee/MongoManager.coffee index 7bdedcbe98..536bf77168 100644 --- a/services/track-changes/app/coffee/MongoManager.coffee +++ b/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 } diff --git a/services/track-changes/test/acceptance/coffee/AppendingUpdatesTests.coffee b/services/track-changes/test/acceptance/coffee/AppendingUpdatesTests.coffee index 070ac4eb66..a82767e7c5 100644 --- a/services/track-changes/test/acceptance/coffee/AppendingUpdatesTests.coffee +++ b/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 diff --git a/services/track-changes/test/unit/coffee/MongoManager/MongoManagerTests.coffee b/services/track-changes/test/unit/coffee/MongoManager/MongoManagerTests.coffee index 737500ee48..186aac8a62 100644 --- a/services/track-changes/test/unit/coffee/MongoManager/MongoManagerTests.coffee +++ b/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),