From 3d000bcbe67603aa22b44b6f33f59de8b450b594 Mon Sep 17 00:00:00 2001 From: Eric Mc Sween Date: Thu, 14 May 2020 17:05:59 -0400 Subject: [PATCH] Decaf cleanup: use arrow functions for callbacks --- .../document-updater/app/js/ProjectManager.js | 117 +++++++++--------- 1 file changed, 57 insertions(+), 60 deletions(-) diff --git a/services/document-updater/app/js/ProjectManager.js b/services/document-updater/app/js/ProjectManager.js index 16997df3cf..25de54f3d1 100644 --- a/services/document-updater/app/js/ProjectManager.js +++ b/services/document-updater/app/js/ProjectManager.js @@ -15,15 +15,13 @@ module.exports = { _callback(...args) } - RedisManager.getDocIdsInProject(projectId, function (error, docIds) { + RedisManager.getDocIdsInProject(projectId, (error, docIds) => { if (error) { return callback(error) } const errors = [] const jobs = docIds.map((docId) => (callback) => { - DocumentManager.flushDocIfLoadedWithLock(projectId, docId, function ( - error - ) { + DocumentManager.flushDocIfLoadedWithLock(projectId, docId, (error) => { if (error instanceof Errors.NotFoundError) { logger.warn( { err: error, projectId, docId }, @@ -41,7 +39,7 @@ module.exports = { }) logger.log({ projectId, docIds }, 'flushing docs') - async.series(jobs, function () { + async.series(jobs, () => { if (errors.length > 0) { callback(new Error('Errors flushing docs. See log for details')) } else { @@ -60,7 +58,7 @@ module.exports = { _callback(...args) } - RedisManager.getDocIdsInProject(projectId, function (error, docIds) { + RedisManager.getDocIdsInProject(projectId, (error, docIds) => { if (error) { return callback(error) } @@ -70,7 +68,7 @@ module.exports = { projectId, docId, {}, - function (error) { + (error) => { if (error) { logger.error( { err: error, projectId, docId }, @@ -89,9 +87,7 @@ module.exports = { // history is completely flushed because the project may be // deleted in web after this call completes, and so further // attempts to flush would fail after that. - HistoryManager.flushProjectChanges(projectId, options, function ( - error - ) { + HistoryManager.flushProjectChanges(projectId, options, (error) => { if (errors.length > 0) { callback(new Error('Errors deleting docs. See log for details')) } else if (error) { @@ -105,7 +101,7 @@ module.exports = { }, queueFlushAndDeleteProject(projectId, callback) { - RedisManager.queueFlushAndDeleteProject(projectId, function (error) { + RedisManager.queueFlushAndDeleteProject(projectId, (error) => { if (error) { logger.error( { projectId, error }, @@ -119,14 +115,14 @@ module.exports = { }, getProjectDocsTimestamps(projectId, callback) { - RedisManager.getDocIdsInProject(projectId, function (error, docIds) { + RedisManager.getDocIdsInProject(projectId, (error, docIds) => { if (error) { return callback(error) } if (docIds.length === 0) { return callback(null, []) } - RedisManager.getDocTimestamps(docIds, function (error, timestamps) { + RedisManager.getDocTimestamps(docIds, (error, timestamps) => { if (error) { return callback(error) } @@ -149,58 +145,59 @@ module.exports = { _callback(...args) } - RedisManager.checkOrSetProjectState(projectId, projectStateHash, function ( - error, - projectStateChanged - ) { - if (error) { - logger.error( - { err: error, projectId }, - 'error getting/setting project state in getProjectDocsAndFlushIfOld' - ) - return callback(error) - } - // we can't return docs if project structure has changed - if (projectStateChanged) { - return callback( - Errors.ProjectStateChangedError('project state changed') - ) - } - // project structure hasn't changed, return doc content from redis - RedisManager.getDocIdsInProject(projectId, function (error, docIds) { + RedisManager.checkOrSetProjectState( + projectId, + projectStateHash, + (error, projectStateChanged) => { if (error) { logger.error( { err: error, projectId }, - 'error getting doc ids in getProjectDocs' + 'error getting/setting project state in getProjectDocsAndFlushIfOld' ) return callback(error) } - // get the doc lines from redis - const jobs = docIds.map((docId) => (cb) => { - DocumentManager.getDocAndFlushIfOldWithLock( - projectId, - docId, - function (err, lines, version) { - if (err) { - logger.error( - { err, projectId, docId }, - 'error getting project doc lines in getProjectDocsAndFlushIfOld' - ) - return cb(err) - } - const doc = { _id: docId, lines, v: version } // create a doc object to return - cb(null, doc) - } + // we can't return docs if project structure has changed + if (projectStateChanged) { + return callback( + Errors.ProjectStateChangedError('project state changed') ) - }) - async.series(jobs, function (error, docs) { + } + // project structure hasn't changed, return doc content from redis + RedisManager.getDocIdsInProject(projectId, (error, docIds) => { if (error) { + logger.error( + { err: error, projectId }, + 'error getting doc ids in getProjectDocs' + ) return callback(error) } - callback(null, docs) + // get the doc lines from redis + const jobs = docIds.map((docId) => (cb) => { + DocumentManager.getDocAndFlushIfOldWithLock( + projectId, + docId, + (err, lines, version) => { + if (err) { + logger.error( + { err, projectId, docId }, + 'error getting project doc lines in getProjectDocsAndFlushIfOld' + ) + return cb(err) + } + const doc = { _id: docId, lines, v: version } // create a doc object to return + cb(null, doc) + } + ) + }) + async.series(jobs, (error, docs) => { + if (error) { + return callback(error) + } + callback(null, docs) + }) }) - }) - }) + } + ) }, clearProjectState(projectId, callback) { @@ -238,7 +235,7 @@ module.exports = { docId, userId, projectUpdate, - function (error, count) { + (error, count) => { projectOpsLength = count cb(error) } @@ -250,7 +247,7 @@ module.exports = { userId, projectUpdate, projectHistoryId, - function (error, count) { + (error, count) => { projectOpsLength = count cb(error) } @@ -269,7 +266,7 @@ module.exports = { fileId, userId, projectUpdate, - function (error, count) { + (error, count) => { projectOpsLength = count cb(error) } @@ -282,7 +279,7 @@ module.exports = { fileId, userId, projectUpdate, - function (error, count) { + (error, count) => { projectOpsLength = count cb(error) } @@ -290,11 +287,11 @@ module.exports = { } } - async.eachSeries(docUpdates, handleDocUpdate, function (error) { + async.eachSeries(docUpdates, handleDocUpdate, (error) => { if (error) { return callback(error) } - async.eachSeries(fileUpdates, handleFileUpdate, function (error) { + async.eachSeries(fileUpdates, handleFileUpdate, (error) => { if (error) { return callback(error) }