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