mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Remove old history deletion method
This commit is contained in:
parent
cc962e1c44
commit
eb7bcc6922
8 changed files with 7 additions and 84 deletions
|
@ -7,8 +7,6 @@ Metrics = require "metrics-sharelatex"
|
|||
Metrics.initialize("track-changes")
|
||||
Metrics.mongodb.monitor(Path.resolve(__dirname + "/node_modules/mongojs/node_modules/mongodb"), logger)
|
||||
|
||||
require("./app/js/MongoManager").ensureIndices()
|
||||
|
||||
HttpController = require "./app/js/HttpController"
|
||||
express = require "express"
|
||||
app = express()
|
||||
|
|
|
@ -82,12 +82,6 @@ module.exports = MongoManager =
|
|||
|
||||
cursor.toArray callback
|
||||
|
||||
deleteOldProjectUpdates: (project_id, before, callback = (error) ->) ->
|
||||
db.docHistory.remove {
|
||||
project_id: ObjectId(project_id)
|
||||
"meta.end_ts": { $lt: before }
|
||||
}, callback
|
||||
|
||||
backportProjectId: (project_id, doc_id, callback = (error) ->) ->
|
||||
db.docHistory.update {
|
||||
doc_id: ObjectId(doc_id.toString())
|
||||
|
|
|
@ -19,14 +19,3 @@ module.exports = UpdateTrimmer =
|
|||
else
|
||||
callback null, true
|
||||
|
||||
deleteOldProjectUpdates: (project_id, callback = (error) ->) ->
|
||||
UpdateTrimmer.shouldTrimUpdates project_id, (error, shouldTrim) ->
|
||||
return callback(error) if error?
|
||||
if shouldTrim
|
||||
logger.log project_id: project_id, "deleting old updates"
|
||||
oneWeek = 7 * 24 * 60 * 60 * 1000
|
||||
before = Date.now() - oneWeek
|
||||
MongoManager.deleteOldProjectUpdates project_id, before, callback
|
||||
else
|
||||
logger.log project_id: project_id, "not deleting old updates"
|
||||
callback()
|
|
@ -77,9 +77,7 @@ module.exports = UpdatesManager =
|
|||
do (doc_id) ->
|
||||
jobs.push (callback) ->
|
||||
UpdatesManager.processUncompressedUpdatesWithLock project_id, doc_id, callback
|
||||
async.parallelLimit jobs, 5, (error) ->
|
||||
return callback(error) if error?
|
||||
UpdateTrimmer.deleteOldProjectUpdates project_id, callback
|
||||
async.parallelLimit jobs, 5, callback
|
||||
|
||||
getDocUpdates: (project_id, doc_id, options = {}, callback = (error, updates) ->) ->
|
||||
UpdatesManager.processUncompressedUpdatesWithLock project_id, doc_id, (error) ->
|
||||
|
|
|
@ -63,9 +63,9 @@ describe "Flushing updates", ->
|
|||
throw error if error?
|
||||
done()
|
||||
|
||||
it "should not delete the old updates", (done) ->
|
||||
it "should not mark the updates for deletion", (done) ->
|
||||
TrackChangesClient.getCompressedUpdates @doc_id, (error, updates) ->
|
||||
expect(updates.length).to.equal 2
|
||||
expect(updates[0].expiresAt).to.not.exist
|
||||
done()
|
||||
|
||||
it "should preserve history forever", (done) ->
|
||||
|
@ -99,10 +99,9 @@ describe "Flushing updates", ->
|
|||
throw error if error?
|
||||
done()
|
||||
|
||||
it "should delete the older update, but the newer update", (done) ->
|
||||
it "should mark the updates for deletion", (done) ->
|
||||
TrackChangesClient.getCompressedUpdates @doc_id, (error, updates) ->
|
||||
expect(updates.length).to.equal 1
|
||||
expect(updates[0].op).to.deep.equal [{ i: "f", p: 3 }]
|
||||
expect(updates[0].expiresAt).to.exist
|
||||
done()
|
||||
|
||||
describe "without versioning enabled but with preserveHistory set to true", ->
|
||||
|
@ -133,7 +132,7 @@ describe "Flushing updates", ->
|
|||
throw error if error?
|
||||
done()
|
||||
|
||||
it "should not delete the old updates", (done) ->
|
||||
it "should not mark the updates for deletion", (done) ->
|
||||
TrackChangesClient.getCompressedUpdates @doc_id, (error, updates) ->
|
||||
expect(updates.length).to.equal 2
|
||||
expect(updates[0].expiresAt).to.not.exist
|
||||
done()
|
||||
|
|
|
@ -336,21 +336,3 @@ describe "MongoManager", ->
|
|||
|
||||
it "should call the callback", ->
|
||||
@callback.called.should.equal true
|
||||
|
||||
describe "deleteOldProjectUpdates", ->
|
||||
beforeEach ->
|
||||
@before = Date.now() - 10000
|
||||
@db.docHistory =
|
||||
remove: sinon.stub().callsArg(1)
|
||||
@MongoManager.deleteOldProjectUpdates @project_id, @before, @callback
|
||||
|
||||
it "should delete updates before the 'before' time", ->
|
||||
@db.docHistory.remove
|
||||
.calledWith({
|
||||
project_id: ObjectId(@project_id)
|
||||
"meta.end_ts": { "$lt": @before }
|
||||
})
|
||||
.should.equal true
|
||||
|
||||
it "should return the callback", ->
|
||||
@callback.called.should.equal true
|
||||
|
|
|
@ -109,34 +109,3 @@ describe "UpdateTrimmer", ->
|
|||
it "should return true", ->
|
||||
@callback.calledWith(null, true).should.equal true
|
||||
|
||||
describe "deleteOldProjectUpdates", ->
|
||||
beforeEach ->
|
||||
@oneWeek = 7 * 24 * 60 * 60 * 1000
|
||||
@MongoManager.deleteOldProjectUpdates = sinon.stub().callsArg(2)
|
||||
|
||||
describe "when the updates should be trimmed", ->
|
||||
beforeEach ->
|
||||
@UpdateTrimmer.shouldTrimUpdates = sinon.stub().callsArgWith(1, null, true)
|
||||
@UpdateTrimmer.deleteOldProjectUpdates @project_id, @callback
|
||||
|
||||
it "should delete week old updates in mongo", ->
|
||||
before = Date.now() - @oneWeek
|
||||
@MongoManager.deleteOldProjectUpdates
|
||||
.calledWith(@project_id, before)
|
||||
.should.equal true
|
||||
|
||||
it 'should call the callback', ->
|
||||
@callback.called.should.equal true
|
||||
|
||||
describe "when the updates should not be trimmed", ->
|
||||
beforeEach ->
|
||||
@UpdateTrimmer.shouldTrimUpdates = sinon.stub().callsArgWith(1, null, false)
|
||||
@UpdateTrimmer.deleteOldProjectUpdates @project_id, @callback
|
||||
|
||||
it "should not delete any updates in mongo", ->
|
||||
@MongoManager.deleteOldProjectUpdates
|
||||
.called
|
||||
.should.equal false
|
||||
|
||||
it 'should call the callback', ->
|
||||
@callback.called.should.equal true
|
||||
|
|
|
@ -285,7 +285,6 @@ describe "UpdatesManager", ->
|
|||
@doc_ids = ["mock-id-1", "mock-id-2"]
|
||||
@UpdatesManager.processUncompressedUpdatesWithLock = sinon.stub().callsArg(2)
|
||||
@RedisManager.getDocIdsWithHistoryOps = sinon.stub().callsArgWith(1, null, @doc_ids)
|
||||
@UpdateTrimmer.deleteOldProjectUpdates = sinon.stub().callsArg(1)
|
||||
@UpdatesManager.processUncompressedUpdatesForProject @project_id, () =>
|
||||
@callback()
|
||||
done()
|
||||
|
@ -301,11 +300,6 @@ describe "UpdatesManager", ->
|
|||
.calledWith(@project_id, doc_id)
|
||||
.should.equal true
|
||||
|
||||
it "should delete old updates for the project", ->
|
||||
@UpdateTrimmer.deleteOldProjectUpdates
|
||||
.calledWith(@project_id)
|
||||
.should.equal true
|
||||
|
||||
it "should call the callback", ->
|
||||
@callback.called.should.equal true
|
||||
|
||||
|
|
Loading…
Reference in a new issue