mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Add in project flushing end point
This commit is contained in:
parent
8cae726838
commit
bd4bb3d3cf
4 changed files with 42 additions and 7 deletions
|
@ -10,12 +10,14 @@ app = express()
|
|||
|
||||
app.use express.logger()
|
||||
|
||||
app.post "/project/:project_id/doc/:doc_id/flush", HttpController.flushUpdatesWithLock
|
||||
app.post "/project/:project_id/doc/:doc_id/flush", HttpController.flushDoc
|
||||
|
||||
app.get "/project/:project_id/doc/:doc_id/diff", HttpController.getDiff
|
||||
|
||||
app.get "/project/:project_id/updates", HttpController.getUpdates
|
||||
|
||||
app.post "/project/:project_id/flush", HttpController.flushProject
|
||||
|
||||
app.post "/project/:project_id/doc/:doc_id/version/:version/restore", HttpController.restore
|
||||
|
||||
app.get "/status", (req, res, next) ->
|
||||
|
|
|
@ -4,14 +4,21 @@ RestoreManager = require "./RestoreManager"
|
|||
logger = require "logger-sharelatex"
|
||||
|
||||
module.exports = HttpController =
|
||||
flushUpdatesWithLock: (req, res, next = (error) ->) ->
|
||||
flushDoc: (req, res, next = (error) ->) ->
|
||||
doc_id = req.params.doc_id
|
||||
project_id = req.params.project_id
|
||||
logger.log doc_id: doc_id, "compressing doc history"
|
||||
logger.log project_id: project_id, doc_id: doc_id, "compressing doc history"
|
||||
UpdatesManager.processUncompressedUpdatesWithLock project_id, doc_id, (error) ->
|
||||
return next(error) if error?
|
||||
res.send 204
|
||||
|
||||
flushProject: (req, res, next = (error) ->) ->
|
||||
project_id = req.params.project_id
|
||||
logger.log project_id: project_id, "compressing project history"
|
||||
UpdatesManager.processUncompressedUpdatesForProject project_id, (error) ->
|
||||
return next(error) if error?
|
||||
res.send 204
|
||||
|
||||
getDiff: (req, res, next = (error) ->) ->
|
||||
doc_id = req.params.doc_id
|
||||
project_id = req.params.project_id
|
||||
|
|
|
@ -4,17 +4,24 @@ rclient = require("redis").createClient() # Only works locally for now
|
|||
|
||||
module.exports = TrackChangesClient =
|
||||
flushAndGetCompressedUpdates: (project_id, doc_id, callback = (error, updates) ->) ->
|
||||
TrackChangesClient.flushUpdates project_id, doc_id, (error) ->
|
||||
TrackChangesClient.flushDoc project_id, doc_id, (error) ->
|
||||
return callback(error) if error?
|
||||
TrackChangesClient.getCompressedUpdates doc_id, callback
|
||||
|
||||
flushUpdates: (project_id, doc_id, callback = (error) ->) ->
|
||||
flushDoc: (project_id, doc_id, callback = (error) ->) ->
|
||||
request.post {
|
||||
url: "http://localhost:3015/project/#{project_id}/doc/#{doc_id}/flush"
|
||||
}, (error, response, body) =>
|
||||
response.statusCode.should.equal 204
|
||||
callback(error)
|
||||
|
||||
flushProject: (project_id, callback = (error) ->) ->
|
||||
request.post {
|
||||
url: "http://localhost:3015/project/#{project_id}/flush"
|
||||
}, (error, response, body) =>
|
||||
response.statusCode.should.equal 204
|
||||
callback(error)
|
||||
|
||||
getCompressedUpdates: (doc_id, callback = (error, updates) ->) ->
|
||||
db.docHistory
|
||||
.find(doc_id: ObjectId(doc_id))
|
||||
|
|
|
@ -18,7 +18,7 @@ describe "HttpController", ->
|
|||
@user_id = "mock-user-123"
|
||||
@now = Date.now()
|
||||
|
||||
describe "flushUpdatesWithLock", ->
|
||||
describe "flushDoc", ->
|
||||
beforeEach ->
|
||||
@req =
|
||||
params:
|
||||
|
@ -27,7 +27,7 @@ describe "HttpController", ->
|
|||
@res =
|
||||
send: sinon.stub()
|
||||
@UpdatesManager.processUncompressedUpdatesWithLock = sinon.stub().callsArg(2)
|
||||
@HttpController.flushUpdatesWithLock @req, @res, @next
|
||||
@HttpController.flushDoc @req, @res, @next
|
||||
|
||||
it "should process the updates", ->
|
||||
@UpdatesManager.processUncompressedUpdatesWithLock
|
||||
|
@ -37,6 +37,25 @@ describe "HttpController", ->
|
|||
it "should return a success code", ->
|
||||
@res.send.calledWith(204).should.equal true
|
||||
|
||||
describe "flushProject", ->
|
||||
beforeEach ->
|
||||
@req =
|
||||
params:
|
||||
project_id: @project_id
|
||||
@res =
|
||||
send: sinon.stub()
|
||||
@UpdatesManager.processUncompressedUpdatesForProject = sinon.stub().callsArg(1)
|
||||
@HttpController.flushProject @req, @res, @next
|
||||
|
||||
it "should process the updates", ->
|
||||
@UpdatesManager.processUncompressedUpdatesForProject
|
||||
.calledWith(@project_id)
|
||||
.should.equal true
|
||||
|
||||
it "should return a success code", ->
|
||||
@res.send.calledWith(204).should.equal true
|
||||
|
||||
|
||||
describe "getDiff", ->
|
||||
beforeEach ->
|
||||
@from = 42
|
||||
|
|
Loading…
Reference in a new issue