Use expiresAt rather than tempCreatedAt

This commit is contained in:
James Allen 2014-05-16 16:41:14 +01:00
parent 8b0b79bc32
commit 29ad81c134
3 changed files with 13 additions and 12 deletions

View file

@ -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 }

View file

@ -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

View file

@ -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),