Decaf cleanup: camel case variables

This commit is contained in:
Eric Mc Sween 2020-05-11 11:07:15 -04:00
parent fc73bbe1a5
commit 64a881461f

View file

@ -1,7 +1,3 @@
/* eslint-disable
camelcase,
handle-callback-err,
*/
let HttpController
const DocumentManager = require('./DocumentManager')
const HistoryManager = require('./HistoryManager')
@ -18,9 +14,9 @@ const TWO_MEGABYTES = 2 * 1024 * 1024
module.exports = HttpController = {
getDoc(req, res, next) {
let fromVersion
const { doc_id } = req.params
const { project_id } = req.params
logger.log({ project_id, doc_id }, 'getting doc via http')
const docId = req.params.doc_id
const projectId = req.params.project_id
logger.log({ projectId, docId }, 'getting doc via http')
const timer = new Metrics.Timer('http.getDoc')
if (req.query.fromVersion != null) {
@ -30,20 +26,20 @@ module.exports = HttpController = {
}
DocumentManager.getDocAndRecentOpsWithLock(
project_id,
doc_id,
projectId,
docId,
fromVersion,
function (error, lines, version, ops, ranges, pathname) {
timer.done()
if (error) {
return next(error)
}
logger.log({ project_id, doc_id }, 'got doc via http')
logger.log({ projectId, docId }, 'got doc via http')
if (lines == null || version == null) {
return next(new Errors.NotFoundError('document not found'))
}
res.json({
id: doc_id,
id: docId,
lines,
version,
ops,
@ -63,12 +59,12 @@ module.exports = HttpController = {
},
getProjectDocsAndFlushIfOld(req, res, next) {
const { project_id } = req.params
const projectId = req.params.project_id
const projectStateHash = req.query.state
// exclude is string of existing docs "id:version,id:version,..."
const excludeItems =
req.query.exclude != null ? req.query.exclude.split(',') : []
logger.log({ project_id, exclude: excludeItems }, 'getting docs via http')
logger.log({ projectId, exclude: excludeItems }, 'getting docs via http')
const timer = new Metrics.Timer('http.getAllDocs')
const excludeVersions = {}
for (const item of excludeItems) {
@ -76,11 +72,11 @@ module.exports = HttpController = {
excludeVersions[id] = version
}
logger.log(
{ project_id, projectStateHash, excludeVersions },
{ projectId, projectStateHash, excludeVersions },
'excluding versions'
)
ProjectManager.getProjectDocsAndFlushIfOld(
project_id,
projectId,
projectStateHash,
excludeVersions,
function (error, result) {
@ -92,7 +88,7 @@ module.exports = HttpController = {
} else {
logger.log(
{
project_id,
projectId,
result: result.map((doc) => `${doc._id}:${doc.v}`)
},
'got docs via http'
@ -104,10 +100,10 @@ module.exports = HttpController = {
},
clearProjectState(req, res, next) {
const { project_id } = req.params
const projectId = req.params.project_id
const timer = new Metrics.Timer('http.clearProjectState')
logger.log({ project_id }, 'clearing project state via http')
ProjectManager.clearProjectState(project_id, function (error) {
logger.log({ projectId }, 'clearing project state via http')
ProjectManager.clearProjectState(projectId, function (error) {
timer.done()
if (error) {
next(error)
@ -118,99 +114,99 @@ module.exports = HttpController = {
},
setDoc(req, res, next) {
const { doc_id } = req.params
const { project_id } = req.params
const { lines, source, user_id, undoing } = req.body
const docId = req.params.doc_id
const projectId = req.params.project_id
const { lines, source, user_id: userId, undoing } = req.body
const lineSize = HttpController._getTotalSizeOfLines(lines)
if (lineSize > TWO_MEGABYTES) {
logger.log(
{ project_id, doc_id, source, lineSize, user_id },
{ projectId, docId, source, lineSize, userId },
'document too large, returning 406 response'
)
return res.sendStatus(406)
}
logger.log(
{ project_id, doc_id, lines, source, user_id, undoing },
{ projectId, docId, lines, source, userId, undoing },
'setting doc via http'
)
const timer = new Metrics.Timer('http.setDoc')
DocumentManager.setDocWithLock(
project_id,
doc_id,
projectId,
docId,
lines,
source,
user_id,
userId,
undoing,
function (error) {
timer.done()
if (error) {
return next(error)
}
logger.log({ project_id, doc_id }, 'set doc via http')
logger.log({ projectId, docId }, 'set doc via http')
res.sendStatus(204)
}
)
}, // No Content
flushDocIfLoaded(req, res, next) {
const { doc_id } = req.params
const { project_id } = req.params
logger.log({ project_id, doc_id }, 'flushing doc via http')
const docId = req.params.doc_id
const projectId = req.params.project_id
logger.log({ projectId, docId }, 'flushing doc via http')
const timer = new Metrics.Timer('http.flushDoc')
DocumentManager.flushDocIfLoadedWithLock(project_id, doc_id, function (
DocumentManager.flushDocIfLoadedWithLock(projectId, docId, function (
error
) {
timer.done()
if (error) {
return next(error)
}
logger.log({ project_id, doc_id }, 'flushed doc via http')
logger.log({ projectId, docId }, 'flushed doc via http')
res.sendStatus(204)
})
}, // No Content
deleteDoc(req, res, next) {
const { doc_id } = req.params
const { project_id } = req.params
const docId = req.params.doc_id
const projectId = req.params.project_id
const ignoreFlushErrors = req.query.ignore_flush_errors === 'true'
const timer = new Metrics.Timer('http.deleteDoc')
logger.log({ project_id, doc_id }, 'deleting doc via http')
logger.log({ projectId, docId }, 'deleting doc via http')
DocumentManager.flushAndDeleteDocWithLock(
project_id,
doc_id,
projectId,
docId,
{ ignoreFlushErrors },
function (error) {
timer.done()
// There is no harm in flushing project history if the previous call
// failed and sometimes it is required
HistoryManager.flushProjectChangesAsync(project_id)
HistoryManager.flushProjectChangesAsync(projectId)
if (error) {
return next(error)
}
logger.log({ project_id, doc_id }, 'deleted doc via http')
logger.log({ projectId, docId }, 'deleted doc via http')
res.sendStatus(204)
}
)
}, // No Content
flushProject(req, res, next) {
const { project_id } = req.params
logger.log({ project_id }, 'flushing project via http')
const projectId = req.params.project_id
logger.log({ projectId }, 'flushing project via http')
const timer = new Metrics.Timer('http.flushProject')
ProjectManager.flushProjectWithLocks(project_id, function (error) {
ProjectManager.flushProjectWithLocks(projectId, function (error) {
timer.done()
if (error) {
return next(error)
}
logger.log({ project_id }, 'flushed project via http')
logger.log({ projectId }, 'flushed project via http')
res.sendStatus(204)
})
}, // No Content
deleteProject(req, res, next) {
const { project_id } = req.params
logger.log({ project_id }, 'deleting project via http')
const projectId = req.params.project_id
logger.log({ projectId }, 'deleting project via http')
const options = {}
if (req.query.background) {
options.background = true
@ -219,24 +215,24 @@ module.exports = HttpController = {
options.skip_history_flush = true
} // don't flush history when realtime shuts down
if (req.query.background) {
ProjectManager.queueFlushAndDeleteProject(project_id, function (error) {
ProjectManager.queueFlushAndDeleteProject(projectId, function (error) {
if (error) {
return next(error)
}
logger.log({ project_id }, 'queue delete of project via http')
logger.log({ projectId }, 'queue delete of project via http')
res.sendStatus(204)
}) // No Content
} else {
const timer = new Metrics.Timer('http.deleteProject')
ProjectManager.flushAndDeleteProjectWithLocks(
project_id,
projectId,
options,
function (error) {
timer.done()
if (error) {
return next(error)
}
logger.log({ project_id }, 'deleted project via http')
logger.log({ projectId }, 'deleted project via http')
res.sendStatus(204)
}
)
@ -244,13 +240,13 @@ module.exports = HttpController = {
}, // No Content
deleteMultipleProjects(req, res, next) {
const project_ids = req.body.project_ids || []
logger.log({ project_ids }, 'deleting multiple projects via http')
const projectIds = req.body.project_ids || []
logger.log({ projectIds }, 'deleting multiple projects via http')
async.eachSeries(
project_ids,
function (project_id, cb) {
logger.log({ project_id }, 'queue delete of project via http')
ProjectManager.queueFlushAndDeleteProject(project_id, cb)
projectIds,
function (projectId, cb) {
logger.log({ projectId }, 'queue delete of project via http')
ProjectManager.queueFlushAndDeleteProject(projectId, cb)
},
function (error) {
if (error) {
@ -262,51 +258,52 @@ module.exports = HttpController = {
}, // No Content
acceptChanges(req, res, next) {
const { project_id, doc_id } = req.params
let change_ids = req.body.change_ids
if (change_ids == null) {
change_ids = [req.params.change_id]
const { project_id: projectId, doc_id: docId } = req.params
let changeIds = req.body.change_ids
if (changeIds == null) {
changeIds = [req.params.change_id]
}
logger.log(
{ project_id, doc_id },
`accepting ${change_ids.length} changes via http`
{ projectId, docId },
`accepting ${changeIds.length} changes via http`
)
const timer = new Metrics.Timer('http.acceptChanges')
DocumentManager.acceptChangesWithLock(
project_id,
doc_id,
change_ids,
projectId,
docId,
changeIds,
function (error) {
timer.done()
if (error) {
return next(error)
}
logger.log(
{ project_id, doc_id },
`accepted ${change_ids.length} changes via http`
{ projectId, docId },
`accepted ${changeIds.length} changes via http`
)
res.sendStatus(204)
res.sendStatus(204) // No Content
}
)
}, // No Content
},
deleteComment(req, res, next) {
const { project_id, doc_id, comment_id } = req.params
logger.log({ project_id, doc_id, comment_id }, 'deleting comment via http')
const {
project_id: projectId,
doc_id: docId,
comment_id: commentId
} = req.params
logger.log({ projectId, docId, commentId }, 'deleting comment via http')
const timer = new Metrics.Timer('http.deleteComment')
DocumentManager.deleteCommentWithLock(
project_id,
doc_id,
comment_id,
projectId,
docId,
commentId,
function (error) {
timer.done()
if (error) {
return next(error)
}
logger.log(
{ project_id, doc_id, comment_id },
'deleted comment via http'
)
logger.log({ projectId, docId, commentId }, 'deleted comment via http')
res.sendStatus(204)
}
)
@ -314,7 +311,7 @@ module.exports = HttpController = {
updateProject(req, res, next) {
const timer = new Metrics.Timer('http.updateProject')
const { project_id } = req.params
const projectId = req.params.project_id
const {
projectHistoryId,
userId,
@ -323,12 +320,12 @@ module.exports = HttpController = {
version
} = req.body
logger.log(
{ project_id, docUpdates, fileUpdates, version },
{ projectId, docUpdates, fileUpdates, version },
'updating project via http'
)
ProjectManager.updateProjectWithLocks(
project_id,
projectId,
projectHistoryId,
userId,
docUpdates,
@ -339,22 +336,22 @@ module.exports = HttpController = {
if (error) {
return next(error)
}
logger.log({ project_id }, 'updated project via http')
logger.log({ projectId }, 'updated project via http')
res.sendStatus(204)
}
)
}, // No Content
resyncProjectHistory(req, res, next) {
const { project_id } = req.params
const projectId = req.params.project_id
const { projectHistoryId, docs, files } = req.body
logger.log(
{ project_id, docs, files },
{ projectId, docs, files },
'queuing project history resync via http'
)
HistoryManager.resyncProjectHistory(
project_id,
projectId,
projectHistoryId,
docs,
files,
@ -362,7 +359,7 @@ module.exports = HttpController = {
if (error) {
return next(error)
}
logger.log({ project_id }, 'queued project history resync via http')
logger.log({ projectId }, 'queued project history resync via http')
res.sendStatus(204)
}
)
@ -375,12 +372,12 @@ module.exports = HttpController = {
concurrency: req.query.concurrency || 5,
dryRun: req.query.dryRun || false
}
ProjectFlusher.flushAllProjects(options, function (err, project_ids) {
ProjectFlusher.flushAllProjects(options, function (err, projectIds) {
if (err) {
logger.err({ err }, 'error bulk flushing projects')
res.sendStatus(500)
} else {
res.send(project_ids)
res.send(projectIds)
}
})
},