diff --git a/services/document-updater/app/js/ProjectManager.js b/services/document-updater/app/js/ProjectManager.js index 3da062995b..d3dc0b14f7 100644 --- a/services/document-updater/app/js/ProjectManager.js +++ b/services/document-updater/app/js/ProjectManager.js @@ -1,7 +1,3 @@ -/* eslint-disable - camelcase, - handle-callback-err, -*/ const RedisManager = require('./RedisManager') const ProjectHistoryRedisManager = require('./ProjectHistoryRedisManager') const DocumentManager = require('./DocumentManager') @@ -12,35 +8,35 @@ const Metrics = require('./Metrics') const Errors = require('./Errors') module.exports = { - flushProjectWithLocks(project_id, _callback) { + flushProjectWithLocks(projectId, _callback) { const timer = new Metrics.Timer('projectManager.flushProjectWithLocks') const callback = function (...args) { timer.done() _callback(...args) } - RedisManager.getDocIdsInProject(project_id, function (error, doc_ids) { + RedisManager.getDocIdsInProject(projectId, function (error, docIds) { if (error) { return callback(error) } const jobs = [] const errors = [] - for (const doc_id of doc_ids) { - ;((doc_id) => + for (const docId of docIds) { + ;((docId) => jobs.push((callback) => DocumentManager.flushDocIfLoadedWithLock( - project_id, - doc_id, + projectId, + docId, function (error) { if (error instanceof Errors.NotFoundError) { logger.warn( - { err: error, project_id, doc_id }, + { err: error, projectId, docId }, 'found deleted doc when flushing' ) callback() } else if (error) { logger.error( - { err: error, project_id, doc_id }, + { err: error, projectId, docId }, 'error flushing doc' ) errors.push(error) @@ -50,10 +46,10 @@ module.exports = { } } ) - ))(doc_id) + ))(docId) } - logger.log({ project_id, doc_ids }, 'flushing docs') + logger.log({ projectId, docIds }, 'flushing docs') async.series(jobs, function () { if (errors.length > 0) { callback(new Error('Errors flushing docs. See log for details')) @@ -64,7 +60,7 @@ module.exports = { }) }, - flushAndDeleteProjectWithLocks(project_id, options, _callback) { + flushAndDeleteProjectWithLocks(projectId, options, _callback) { const timer = new Metrics.Timer( 'projectManager.flushAndDeleteProjectWithLocks' ) @@ -73,23 +69,23 @@ module.exports = { _callback(...args) } - RedisManager.getDocIdsInProject(project_id, function (error, doc_ids) { + RedisManager.getDocIdsInProject(projectId, function (error, docIds) { if (error) { return callback(error) } const jobs = [] const errors = [] - for (const doc_id of doc_ids) { - ;((doc_id) => + for (const docId of docIds) { + ;((docId) => jobs.push((callback) => DocumentManager.flushAndDeleteDocWithLock( - project_id, - doc_id, + projectId, + docId, {}, function (error) { if (error) { logger.error( - { err: error, project_id, doc_id }, + { err: error, projectId, docId }, 'error deleting doc' ) errors.push(error) @@ -97,16 +93,16 @@ module.exports = { callback() } ) - ))(doc_id) + ))(docId) } - logger.log({ project_id, doc_ids }, 'deleting docs') + logger.log({ projectId, docIds }, 'deleting docs') async.series(jobs, () => // When deleting the project here we want to ensure that project // 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(project_id, options, function ( + HistoryManager.flushProjectChanges(projectId, options, function ( error ) { if (errors.length > 0) { @@ -121,11 +117,11 @@ module.exports = { }) }, - queueFlushAndDeleteProject(project_id, callback) { - RedisManager.queueFlushAndDeleteProject(project_id, function (error) { + queueFlushAndDeleteProject(projectId, callback) { + RedisManager.queueFlushAndDeleteProject(projectId, function (error) { if (error) { logger.error( - { project_id, error }, + { projectId, error }, 'error adding project to flush and delete queue' ) return callback(error) @@ -135,15 +131,15 @@ module.exports = { }) }, - getProjectDocsTimestamps(project_id, callback) { - RedisManager.getDocIdsInProject(project_id, function (error, doc_ids) { + getProjectDocsTimestamps(projectId, callback) { + RedisManager.getDocIdsInProject(projectId, function (error, docIds) { if (error) { return callback(error) } - if (doc_ids.length === 0) { + if (docIds.length === 0) { return callback(null, []) } - RedisManager.getDocTimestamps(doc_ids, function (error, timestamps) { + RedisManager.getDocTimestamps(docIds, function (error, timestamps) { if (error) { return callback(error) } @@ -153,7 +149,7 @@ module.exports = { }, getProjectDocsAndFlushIfOld( - project_id, + projectId, projectStateHash, excludeVersions, _callback @@ -166,13 +162,13 @@ module.exports = { _callback(...args) } - RedisManager.checkOrSetProjectState(project_id, projectStateHash, function ( + RedisManager.checkOrSetProjectState(projectId, projectStateHash, function ( error, projectStateChanged ) { if (error) { logger.error( - { err: error, project_id }, + { err: error, projectId }, 'error getting/setting project state in getProjectDocsAndFlushIfOld' ) return callback(error) @@ -184,36 +180,36 @@ module.exports = { ) } // project structure hasn't changed, return doc content from redis - RedisManager.getDocIdsInProject(project_id, function (error, doc_ids) { + RedisManager.getDocIdsInProject(projectId, function (error, docIds) { if (error) { logger.error( - { err: error, project_id }, + { err: error, projectId }, 'error getting doc ids in getProjectDocs' ) return callback(error) } const jobs = [] - for (const doc_id of doc_ids) { - ;((doc_id) => + for (const docId of docIds) { + ;((docId) => jobs.push(( cb // get the doc lines from redis ) => DocumentManager.getDocAndFlushIfOldWithLock( - project_id, - doc_id, + projectId, + docId, function (err, lines, version) { if (err) { logger.error( - { err, project_id, doc_id }, + { err, projectId, docId }, 'error getting project doc lines in getProjectDocsAndFlushIfOld' ) return cb(err) } - const doc = { _id: doc_id, lines, v: version } // create a doc object to return + const doc = { _id: docId, lines, v: version } // create a doc object to return cb(null, doc) } ) - ))(doc_id) + ))(docId) } async.series(jobs, function (error, docs) { if (error) { @@ -225,14 +221,14 @@ module.exports = { }) }, - clearProjectState(project_id, callback) { - RedisManager.clearProjectState(project_id, callback) + clearProjectState(projectId, callback) { + RedisManager.clearProjectState(projectId, callback) }, updateProjectWithLocks( - project_id, + projectId, projectHistoryId, - user_id, + userId, docUpdates, fileUpdates, version, @@ -244,36 +240,36 @@ module.exports = { _callback(...args) } - const project_version = version - let project_subversion = 0 // project versions can have multiple operations + const projectVersion = version + let projectSubversion = 0 // project versions can have multiple operations - let project_ops_length = 0 + let projectOpsLength = 0 const handleDocUpdate = function (projectUpdate, cb) { - const doc_id = projectUpdate.id - projectUpdate.version = `${project_version}.${project_subversion++}` + const docId = projectUpdate.id + projectUpdate.version = `${projectVersion}.${projectSubversion++}` if (projectUpdate.docLines != null) { ProjectHistoryRedisManager.queueAddEntity( - project_id, + projectId, projectHistoryId, 'doc', - doc_id, - user_id, + docId, + userId, projectUpdate, function (error, count) { - project_ops_length = count + projectOpsLength = count cb(error) } ) } else { DocumentManager.renameDocWithLock( - project_id, - doc_id, - user_id, + projectId, + docId, + userId, projectUpdate, projectHistoryId, function (error, count) { - project_ops_length = count + projectOpsLength = count cb(error) } ) @@ -281,31 +277,31 @@ module.exports = { } const handleFileUpdate = function (projectUpdate, cb) { - const file_id = projectUpdate.id - projectUpdate.version = `${project_version}.${project_subversion++}` + const fileId = projectUpdate.id + projectUpdate.version = `${projectVersion}.${projectSubversion++}` if (projectUpdate.url != null) { ProjectHistoryRedisManager.queueAddEntity( - project_id, + projectId, projectHistoryId, 'file', - file_id, - user_id, + fileId, + userId, projectUpdate, function (error, count) { - project_ops_length = count + projectOpsLength = count cb(error) } ) } else { ProjectHistoryRedisManager.queueRenameEntity( - project_id, + projectId, projectHistoryId, 'file', - file_id, - user_id, + fileId, + userId, projectUpdate, function (error, count) { - project_ops_length = count + projectOpsLength = count cb(error) } ) @@ -322,12 +318,12 @@ module.exports = { } if ( HistoryManager.shouldFlushHistoryOps( - project_ops_length, + projectOpsLength, docUpdates.length + fileUpdates.length, HistoryManager.FLUSH_PROJECT_EVERY_N_OPS ) ) { - HistoryManager.flushProjectChangesAsync(project_id) + HistoryManager.flushProjectChangesAsync(projectId) } callback() }) diff --git a/services/document-updater/test/unit/js/ProjectManager/flushAndDeleteProjectTests.js b/services/document-updater/test/unit/js/ProjectManager/flushAndDeleteProjectTests.js index 7afa407e7c..266d1d1a2e 100644 --- a/services/document-updater/test/unit/js/ProjectManager/flushAndDeleteProjectTests.js +++ b/services/document-updater/test/unit/js/ProjectManager/flushAndDeleteProjectTests.js @@ -140,7 +140,7 @@ describe('ProjectManager - flushAndDeleteProject', function () { it('should record the error', function () { return this.logger.error .calledWith( - { err: this.error, project_id: this.project_id, doc_id: 'doc-id-1' }, + { err: this.error, projectId: this.project_id, docId: 'doc-id-1' }, 'error deleting doc' ) .should.equal(true) diff --git a/services/document-updater/test/unit/js/ProjectManager/flushProjectTests.js b/services/document-updater/test/unit/js/ProjectManager/flushProjectTests.js index 110a827e64..1907a26228 100644 --- a/services/document-updater/test/unit/js/ProjectManager/flushProjectTests.js +++ b/services/document-updater/test/unit/js/ProjectManager/flushProjectTests.js @@ -129,7 +129,7 @@ describe('ProjectManager - flushProject', function () { it('should record the error', function () { return this.logger.error .calledWith( - { err: this.error, project_id: this.project_id, doc_id: 'doc-id-1' }, + { err: this.error, projectId: this.project_id, docId: 'doc-id-1' }, 'error flushing doc' ) .should.equal(true) diff --git a/services/document-updater/test/unit/js/ProjectManager/getProjectDocsTests.js b/services/document-updater/test/unit/js/ProjectManager/getProjectDocsTests.js index 72ffe39ec1..a10b328864 100644 --- a/services/document-updater/test/unit/js/ProjectManager/getProjectDocsTests.js +++ b/services/document-updater/test/unit/js/ProjectManager/getProjectDocsTests.js @@ -187,7 +187,7 @@ describe('ProjectManager - getProjectDocsAndFlushIfOld', function () { it('should record the error', function () { return this.logger.error .calledWith( - { err: this.error, project_id: this.project_id, doc_id: 'doc-id-2' }, + { err: this.error, projectId: this.project_id, docId: 'doc-id-2' }, 'error getting project doc lines in getProjectDocsAndFlushIfOld' ) .should.equal(true)