mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
peek at docs without fetching from mongo
This commit is contained in:
parent
3ccd3a228f
commit
0fd24b5133
3 changed files with 20 additions and 0 deletions
|
@ -53,6 +53,7 @@ app.param('doc_id', (req, res, next, docId) => {
|
|||
})
|
||||
|
||||
app.get('/project/:project_id/doc/:doc_id', HttpController.getDoc)
|
||||
app.get('/project/:project_id/doc/:doc_id/peek', HttpController.peekDoc)
|
||||
// temporarily keep the GET method for backwards compatibility
|
||||
app.get('/project/:project_id/doc', HttpController.getProjectDocsAndFlushIfOld)
|
||||
// will migrate to the POST method of get_and_flush_if_old instead
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const DocumentManager = require('./DocumentManager')
|
||||
const HistoryManager = require('./HistoryManager')
|
||||
const ProjectManager = require('./ProjectManager')
|
||||
const RedisManager = require('./RedisManager')
|
||||
const Errors = require('./Errors')
|
||||
const logger = require('logger-sharelatex')
|
||||
const Settings = require('@overleaf/settings')
|
||||
|
@ -11,6 +12,7 @@ const async = require('async')
|
|||
|
||||
module.exports = {
|
||||
getDoc,
|
||||
peekDoc,
|
||||
getProjectDocsAndFlushIfOld,
|
||||
clearProjectState,
|
||||
setDoc,
|
||||
|
@ -65,6 +67,22 @@ function getDoc(req, res, next) {
|
|||
)
|
||||
}
|
||||
|
||||
// return the doc from redis if present, but don't load it from mongo
|
||||
function peekDoc(req, res, next) {
|
||||
const docId = req.params.doc_id
|
||||
const projectId = req.params.project_id
|
||||
logger.log({ projectId, docId }, 'peeking at doc via http')
|
||||
RedisManager.getDoc(projectId, docId, function (error, lines, version) {
|
||||
if (error) {
|
||||
return next(error)
|
||||
}
|
||||
if (lines == null || version == null) {
|
||||
return next(new Errors.NotFoundError('document not found'))
|
||||
}
|
||||
res.json({ id: docId, lines, version })
|
||||
})
|
||||
}
|
||||
|
||||
function _getTotalSizeOfLines(lines) {
|
||||
let size = 0
|
||||
for (const line of lines) {
|
||||
|
|
|
@ -14,6 +14,7 @@ describe('HttpController', function () {
|
|||
'./ProjectManager': (this.ProjectManager = {}),
|
||||
'./ProjectFlusher': { flushAllProjects() {} },
|
||||
'./DeleteQueueManager': (this.DeleteQueueManager = {}),
|
||||
'./RedisManager': (this.RedisManager = {}),
|
||||
'./Metrics': (this.Metrics = {}),
|
||||
'./Errors': Errors,
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue