Kaynağa Gözat

Merge pull request #12210 from overleaf/em-camel-case-project-history

Camel case variables in project-history

GitOrigin-RevId: 299245883b44366911ee43ee7e644a7bfa3d8319
Eric Mc Sween 3 yıl önce
ebeveyn
işleme
5fe98bf0fd

+ 10 - 11
services/project-history/app/js/DocumentUpdaterManager.js

@@ -1,5 +1,4 @@
 /* eslint-disable
 /* eslint-disable
-    camelcase,
     no-unused-vars,
     no-unused-vars,
 */
 */
 // TODO: This file was created by bulk-decaffeinate.
 // TODO: This file was created by bulk-decaffeinate.
@@ -15,12 +14,12 @@ import logger from '@overleaf/logger'
 import Settings from '@overleaf/settings'
 import Settings from '@overleaf/settings'
 import OError from '@overleaf/o-error'
 import OError from '@overleaf/o-error'
 
 
-export function getDocument(project_id, doc_id, callback) {
+export function getDocument(projectId, docId, callback) {
   if (callback == null) {
   if (callback == null) {
     callback = function () {}
     callback = function () {}
   }
   }
-  const url = `${Settings.apis.documentupdater.url}/project/${project_id}/doc/${doc_id}`
-  logger.debug({ project_id, doc_id }, 'getting doc from document updater')
+  const url = `${Settings.apis.documentupdater.url}/project/${projectId}/doc/${docId}`
+  logger.debug({ projectId, docId }, 'getting doc from document updater')
   return request.get(url, function (error, res, body) {
   return request.get(url, function (error, res, body) {
     if (error != null) {
     if (error != null) {
       return callback(OError.tag(error))
       return callback(OError.tag(error))
@@ -33,33 +32,33 @@ export function getDocument(project_id, doc_id, callback) {
         return callback(error)
         return callback(error)
       }
       }
       logger.debug(
       logger.debug(
-        { project_id, doc_id, version: body.version },
+        { projectId, docId, version: body.version },
         'got doc from document updater'
         'got doc from document updater'
       )
       )
       return callback(null, body.lines.join('\n'), body.version)
       return callback(null, body.lines.join('\n'), body.version)
     } else {
     } else {
       error = new OError(
       error = new OError(
         `doc updater returned a non-success status code: ${res.statusCode}`,
         `doc updater returned a non-success status code: ${res.statusCode}`,
-        { project_id, doc_id, url }
+        { project_id: projectId, doc_id: docId, url }
       )
       )
       return callback(error)
       return callback(error)
     }
     }
   })
   })
 }
 }
 
 
-export function setDocument(project_id, doc_id, content, user_id, callback) {
+export function setDocument(projectId, docId, content, userId, callback) {
   if (callback == null) {
   if (callback == null) {
     callback = function () {}
     callback = function () {}
   }
   }
-  const url = `${Settings.apis.documentupdater.url}/project/${project_id}/doc/${doc_id}`
-  logger.debug({ project_id, doc_id }, 'setting doc in document updater')
+  const url = `${Settings.apis.documentupdater.url}/project/${projectId}/doc/${docId}`
+  logger.debug({ projectId, docId }, 'setting doc in document updater')
   return request.post(
   return request.post(
     {
     {
       url,
       url,
       json: {
       json: {
         lines: content.split('\n'),
         lines: content.split('\n'),
         source: 'restore',
         source: 'restore',
-        user_id,
+        user_id: userId,
         undoing: true,
         undoing: true,
       },
       },
     },
     },
@@ -72,7 +71,7 @@ export function setDocument(project_id, doc_id, content, user_id, callback) {
       } else {
       } else {
         error = new OError(
         error = new OError(
           `doc updater returned a non-success status code: ${res.statusCode}`,
           `doc updater returned a non-success status code: ${res.statusCode}`,
-          { project_id, doc_id, url }
+          { project_id: projectId, doc_id: docId, url }
         )
         )
         return callback(error)
         return callback(error)
       }
       }

+ 17 - 17
services/project-history/app/js/ErrorRecorder.js

@@ -1,6 +1,3 @@
-/* eslint-disable
-    camelcase,
-*/
 // TODO: This file was created by bulk-decaffeinate.
 // TODO: This file was created by bulk-decaffeinate.
 // Fix any style issues and re-enable lint.
 // Fix any style issues and re-enable lint.
 /*
 /*
@@ -16,14 +13,14 @@ import metrics from '@overleaf/metrics'
 import OError from '@overleaf/o-error'
 import OError from '@overleaf/o-error'
 import { db } from './mongodb.js'
 import { db } from './mongodb.js'
 
 
-export function record(project_id, queueSize, error, callback) {
+export function record(projectId, queueSize, error, callback) {
   if (callback == null) {
   if (callback == null) {
     callback = function () {}
     callback = function () {}
   }
   }
   const _callback = function (mongoError) {
   const _callback = function (mongoError) {
     if (mongoError != null) {
     if (mongoError != null) {
       logger.error(
       logger.error(
-        { project_id, mongoError },
+        { projectId, mongoError },
         'failed to change project statues in mongo'
         'failed to change project statues in mongo'
       )
       )
     }
     }
@@ -38,12 +35,12 @@ export function record(project_id, queueSize, error, callback) {
       ts: new Date(),
       ts: new Date(),
     }
     }
     logger.debug(
     logger.debug(
-      { project_id, errorRecord },
+      { projectId, errorRecord },
       'recording failed attempt to process updates'
       'recording failed attempt to process updates'
     )
     )
     return db.projectHistoryFailures.updateOne(
     return db.projectHistoryFailures.updateOne(
       {
       {
-        project_id,
+        project_id: projectId,
       },
       },
       {
       {
         $set: errorRecord,
         $set: errorRecord,
@@ -64,20 +61,23 @@ export function record(project_id, queueSize, error, callback) {
       _callback
       _callback
     )
     )
   } else {
   } else {
-    return db.projectHistoryFailures.deleteOne({ project_id }, _callback)
+    return db.projectHistoryFailures.deleteOne(
+      { project_id: projectId },
+      _callback
+    )
   }
   }
 }
 }
 
 
-export function setForceDebug(project_id, state, callback) {
+export function setForceDebug(projectId, state, callback) {
   if (state == null) {
   if (state == null) {
     state = true
     state = true
   }
   }
   if (callback == null) {
   if (callback == null) {
     callback = function () {}
     callback = function () {}
   }
   }
-  logger.debug({ project_id, state }, 'setting forceDebug state for project')
+  logger.debug({ projectId, state }, 'setting forceDebug state for project')
   return db.projectHistoryFailures.updateOne(
   return db.projectHistoryFailures.updateOne(
-    { project_id },
+    { project_id: projectId },
     { $set: { forceDebug: state } },
     { $set: { forceDebug: state } },
     { upsert: true },
     { upsert: true },
     callback
     callback
@@ -86,13 +86,13 @@ export function setForceDebug(project_id, state, callback) {
 
 
 // we only record the sync start time, and not the end time, because the
 // we only record the sync start time, and not the end time, because the
 // record should be cleared on success.
 // record should be cleared on success.
-export function recordSyncStart(project_id, callback) {
+export function recordSyncStart(projectId, callback) {
   if (callback == null) {
   if (callback == null) {
     callback = function () {}
     callback = function () {}
   }
   }
   return db.projectHistoryFailures.updateOne(
   return db.projectHistoryFailures.updateOne(
     {
     {
-      project_id,
+      project_id: projectId,
     },
     },
     {
     {
       $currentDate: {
       $currentDate: {
@@ -116,19 +116,19 @@ export function recordSyncStart(project_id, callback) {
   )
   )
 }
 }
 
 
-export function getFailureRecord(project_id, callback) {
+export function getFailureRecord(projectId, callback) {
   if (callback == null) {
   if (callback == null) {
     callback = function () {}
     callback = function () {}
   }
   }
-  return db.projectHistoryFailures.findOne({ project_id }, callback)
+  return db.projectHistoryFailures.findOne({ project_id: projectId }, callback)
 }
 }
 
 
-export function getLastFailure(project_id, callback) {
+export function getLastFailure(projectId, callback) {
   if (callback == null) {
   if (callback == null) {
     callback = function () {}
     callback = function () {}
   }
   }
   return db.projectHistoryFailures.findOneAndUpdate(
   return db.projectHistoryFailures.findOneAndUpdate(
-    { project_id },
+    { project_id: projectId },
     { $inc: { requestCount: 1 } }, // increment the request count every time we check the last failure
     { $inc: { requestCount: 1 } }, // increment the request count every time we check the last failure
     { projection: { error: 1, ts: 1 } },
     { projection: { error: 1, ts: 1 } },
     (err, result) => callback(err, result && result.value)
     (err, result) => callback(err, result && result.value)

+ 8 - 11
services/project-history/app/js/FlushManager.js

@@ -1,6 +1,3 @@
-/* eslint-disable
-    camelcase,
-*/
 // TODO: This file was created by bulk-decaffeinate.
 // TODO: This file was created by bulk-decaffeinate.
 // Fix any style issues and re-enable lint.
 // Fix any style issues and re-enable lint.
 /*
 /*
@@ -18,12 +15,12 @@ import * as RedisManager from './RedisManager.js'
 import * as UpdatesProcessor from './UpdatesProcessor.js'
 import * as UpdatesProcessor from './UpdatesProcessor.js'
 import * as ErrorRecorder from './ErrorRecorder.js'
 import * as ErrorRecorder from './ErrorRecorder.js'
 
 
-export function flushIfOld(project_id, cutoffTime, callback) {
+export function flushIfOld(projectId, cutoffTime, callback) {
   if (callback == null) {
   if (callback == null) {
     callback = function () {}
     callback = function () {}
   }
   }
   return RedisManager.getFirstOpTimestamp(
   return RedisManager.getFirstOpTimestamp(
-    project_id,
+    projectId,
     function (err, firstOpTimestamp) {
     function (err, firstOpTimestamp) {
       if (err != null) {
       if (err != null) {
         return callback(OError.tag(err))
         return callback(OError.tag(err))
@@ -34,10 +31,10 @@ export function flushIfOld(project_id, cutoffTime, callback) {
       // for safety.
       // for safety.
       if (!firstOpTimestamp || firstOpTimestamp < cutoffTime) {
       if (!firstOpTimestamp || firstOpTimestamp < cutoffTime) {
         logger.debug(
         logger.debug(
-          { project_id, firstOpTimestamp, cutoffTime },
+          { projectId, firstOpTimestamp, cutoffTime },
           'flushing old project'
           'flushing old project'
         )
         )
-        return UpdatesProcessor.processUpdatesForProject(project_id, callback)
+        return UpdatesProcessor.processUpdatesForProject(projectId, callback)
       } else {
       } else {
         return callback()
         return callback()
       }
       }
@@ -81,7 +78,7 @@ export function flushOldOps(options, callback) {
         const startTime = new Date()
         const startTime = new Date()
         let count = 0
         let count = 0
         const jobs = projectIds.map(
         const jobs = projectIds.map(
-          project_id =>
+          projectId =>
             function (cb) {
             function (cb) {
               const timeTaken = new Date() - startTime
               const timeTaken = new Date() - startTime
               count++
               count++
@@ -101,14 +98,14 @@ export function flushOldOps(options, callback) {
                 logger.debug({ count }, 'background retries hit limit')
                 logger.debug({ count }, 'background retries hit limit')
                 return cb(new OError('hit limit'))
                 return cb(new OError('hit limit'))
               }
               }
-              if (failedProjects.has(project_id)) {
+              if (failedProjects.has(projectId)) {
                 // skip failed projects
                 // skip failed projects
                 return setTimeout(cb, options.queueDelay || 100) // pause between flushes
                 return setTimeout(cb, options.queueDelay || 100) // pause between flushes
               }
               }
-              return flushIfOld(project_id, cutoffTime, function (err) {
+              return flushIfOld(projectId, cutoffTime, function (err) {
                 if (err != null) {
                 if (err != null) {
                   logger.warn(
                   logger.warn(
-                    { project_id, flushErr: err },
+                    { projectId, flushErr: err },
                     'error flushing old project'
                     'error flushing old project'
                   )
                   )
                 }
                 }

+ 8 - 9
services/project-history/app/js/HealthChecker.js

@@ -1,6 +1,3 @@
-/* eslint-disable
-    camelcase,
-*/
 // TODO: This file was created by bulk-decaffeinate.
 // TODO: This file was created by bulk-decaffeinate.
 // Fix any style issues and re-enable lint.
 // Fix any style issues and re-enable lint.
 /*
 /*
@@ -20,9 +17,9 @@ import * as LockManager from './LockManager.js'
 const { port } = settings.internal.history
 const { port } = settings.internal.history
 
 
 export function check(callback) {
 export function check(callback) {
-  const project_id = ObjectId(settings.history.healthCheck.project_id)
-  const url = `http://localhost:${port}/project/${project_id}`
-  logger.debug({ project_id }, 'running health check')
+  const projectId = ObjectId(settings.history.healthCheck.project_id)
+  const url = `http://localhost:${port}/project/${projectId}`
+  logger.debug({ projectId }, 'running health check')
   const jobs = [
   const jobs = [
     cb =>
     cb =>
       request.get(
       request.get(
@@ -30,7 +27,7 @@ export function check(callback) {
         function (err, res, body) {
         function (err, res, body) {
           if (err != null) {
           if (err != null) {
             OError.tag(err, 'error checking lock for health check', {
             OError.tag(err, 'error checking lock for health check', {
-              project_id,
+              project_id: projectId,
             })
             })
             logger.err(err)
             logger.err(err)
             return cb(err)
             return cb(err)
@@ -46,7 +43,9 @@ export function check(callback) {
         { url: `${url}/flush`, timeout: 10000 },
         { url: `${url}/flush`, timeout: 10000 },
         function (err, res, body) {
         function (err, res, body) {
           if (err != null) {
           if (err != null) {
-            OError.tag(err, 'error flushing for health check', { project_id })
+            OError.tag(err, 'error flushing for health check', {
+              project_id: projectId,
+            })
             logger.err(err)
             logger.err(err)
             return cb(err)
             return cb(err)
           } else if ((res != null ? res.statusCode : undefined) !== 204) {
           } else if ((res != null ? res.statusCode : undefined) !== 204) {
@@ -62,7 +61,7 @@ export function check(callback) {
         function (err, res, body) {
         function (err, res, body) {
           if (err != null) {
           if (err != null) {
             OError.tag(err, 'error getting updates for health check', {
             OError.tag(err, 'error getting updates for health check', {
-              project_id,
+              project_id: projectId,
             })
             })
             logger.err(err)
             logger.err(err)
             return cb(err)
             return cb(err)

+ 2 - 3
services/project-history/app/js/HistoryApiManager.js

@@ -1,5 +1,4 @@
 /* eslint-disable
 /* eslint-disable
-    camelcase,
     no-unused-vars,
     no-unused-vars,
 */
 */
 // TODO: This file was created by bulk-decaffeinate.
 // TODO: This file was created by bulk-decaffeinate.
@@ -13,11 +12,11 @@
 import * as WebApiManager from './WebApiManager.js'
 import * as WebApiManager from './WebApiManager.js'
 import logger from '@overleaf/logger'
 import logger from '@overleaf/logger'
 
 
-export function shouldUseProjectHistory(project_id, callback) {
+export function shouldUseProjectHistory(projectId, callback) {
   if (callback == null) {
   if (callback == null) {
     callback = function () {}
     callback = function () {}
   }
   }
-  return WebApiManager.getHistoryId(project_id, (error, historyId) =>
+  return WebApiManager.getHistoryId(projectId, (error, historyId) =>
     callback(error, historyId != null)
     callback(error, historyId != null)
   )
   )
 }
 }

+ 1 - 2
services/project-history/test/acceptance/js/FileTreeDiffTests.js

@@ -1,5 +1,4 @@
 /* eslint-disable
 /* eslint-disable
-    camelcase,
     no-undef,
     no-undef,
     no-unused-vars,
     no-unused-vars,
 */
 */
@@ -52,7 +51,7 @@ describe('FileTree Diffs', function () {
 
 
       return ProjectHistoryClient.initializeProject(
       return ProjectHistoryClient.initializeProject(
         this.historyId,
         this.historyId,
-        (error, ol_project) => {
+        (error, olProject) => {
           if (error != null) {
           if (error != null) {
             throw error
             throw error
           }
           }

+ 3 - 4
services/project-history/test/acceptance/js/HealthCheckTests.js

@@ -1,5 +1,4 @@
 /* eslint-disable
 /* eslint-disable
-    camelcase,
     no-undef,
     no-undef,
 */
 */
 // TODO: This file was created by bulk-decaffeinate.
 // TODO: This file was created by bulk-decaffeinate.
@@ -23,9 +22,9 @@ const MockWeb = () => nock('http://localhost:3000')
 
 
 describe('Health Check', function () {
 describe('Health Check', function () {
   beforeEach(function (done) {
   beforeEach(function (done) {
-    const project_id = ObjectId()
+    const projectId = ObjectId()
     const historyId = ObjectId().toString()
     const historyId = ObjectId().toString()
-    settings.history.healthCheck = { project_id }
+    settings.history.healthCheck = { project_id: projectId }
     return ProjectHistoryApp.ensureRunning(error => {
     return ProjectHistoryApp.ensureRunning(error => {
       if (error != null) {
       if (error != null) {
         throw error
         throw error
@@ -45,7 +44,7 @@ describe('Health Check', function () {
           },
           },
         })
         })
       MockWeb()
       MockWeb()
-        .get(`/project/${project_id}/details`)
+        .get(`/project/${projectId}/details`)
         .reply(200, {
         .reply(200, {
           name: 'Test Project',
           name: 'Test Project',
           overleaf: {
           overleaf: {

+ 10 - 11
services/project-history/test/acceptance/js/LabelsTests.js

@@ -1,5 +1,4 @@
 /* eslint-disable
 /* eslint-disable
-    camelcase,
     no-undef,
     no-undef,
     no-unused-vars,
     no-unused-vars,
 */
 */
@@ -39,7 +38,7 @@ describe('Labels', function () {
 
 
       return ProjectHistoryClient.initializeProject(
       return ProjectHistoryClient.initializeProject(
         this.historyId,
         this.historyId,
-        (error, ol_project) => {
+        (error, olProject) => {
           if (error != null) {
           if (error != null) {
             throw error
             throw error
           }
           }
@@ -48,7 +47,7 @@ describe('Labels', function () {
             .get(`/project/${this.project_id}/details`)
             .get(`/project/${this.project_id}/details`)
             .reply(200, {
             .reply(200, {
               name: 'Test Project',
               name: 'Test Project',
-              overleaf: { history: { id: ol_project.id } },
+              overleaf: { history: { id: olProject.id } },
             })
             })
 
 
           MockHistoryStore()
           MockHistoryStore()
@@ -139,11 +138,11 @@ describe('Labels', function () {
   })
   })
 
 
   it('can transfer ownership of labels', function (done) {
   it('can transfer ownership of labels', function (done) {
-    const from_user = ObjectId().toString()
-    const to_user = ObjectId().toString()
+    const fromUser = ObjectId().toString()
+    const toUser = ObjectId().toString()
     return ProjectHistoryClient.createLabel(
     return ProjectHistoryClient.createLabel(
       this.project_id,
       this.project_id,
-      from_user,
+      fromUser,
       7,
       7,
       this.comment,
       this.comment,
       this.created_at,
       this.created_at,
@@ -153,7 +152,7 @@ describe('Labels', function () {
         }
         }
         return ProjectHistoryClient.createLabel(
         return ProjectHistoryClient.createLabel(
           this.project_id,
           this.project_id,
-          from_user,
+          fromUser,
           7,
           7,
           this.comment2,
           this.comment2,
           this.created_at,
           this.created_at,
@@ -162,8 +161,8 @@ describe('Labels', function () {
               throw error
               throw error
             }
             }
             return ProjectHistoryClient.transferLabelOwnership(
             return ProjectHistoryClient.transferLabelOwnership(
-              from_user,
-              to_user,
+              fromUser,
+              toUser,
               error => {
               error => {
                 if (error != null) {
                 if (error != null) {
                   throw error
                   throw error
@@ -180,14 +179,14 @@ describe('Labels', function () {
                         comment: label.comment,
                         comment: label.comment,
                         version: label.version,
                         version: label.version,
                         created_at: label.created_at,
                         created_at: label.created_at,
-                        user_id: to_user,
+                        user_id: toUser,
                       },
                       },
                       {
                       {
                         id: label2.id,
                         id: label2.id,
                         comment: label2.comment,
                         comment: label2.comment,
                         version: label2.version,
                         version: label2.version,
                         created_at: label2.created_at,
                         created_at: label2.created_at,
-                        user_id: to_user,
+                        user_id: toUser,
                       },
                       },
                     ])
                     ])
                     return done()
                     return done()

+ 2 - 3
services/project-history/test/acceptance/js/SummarisedUpdatesTests.js

@@ -1,5 +1,4 @@
 /* eslint-disable
 /* eslint-disable
-    camelcase,
     no-undef,
     no-undef,
     no-unused-vars,
     no-unused-vars,
 */
 */
@@ -42,7 +41,7 @@ describe('Summarized updates', function () {
 
 
       return ProjectHistoryClient.initializeProject(
       return ProjectHistoryClient.initializeProject(
         this.historyId,
         this.historyId,
-        (error, ol_project) => {
+        (error, olProject) => {
           if (error != null) {
           if (error != null) {
             throw error
             throw error
           }
           }
@@ -50,7 +49,7 @@ describe('Summarized updates', function () {
             .get(`/project/${this.projectId}/details`)
             .get(`/project/${this.projectId}/details`)
             .reply(200, {
             .reply(200, {
               name: 'Test Project',
               name: 'Test Project',
-              overleaf: { history: { id: ol_project.id } },
+              overleaf: { history: { id: olProject.id } },
             })
             })
 
 
           MockHistoryStore()
           MockHistoryStore()

+ 2 - 3
services/project-history/test/acceptance/js/helpers/HistoryStoreClient.js

@@ -1,5 +1,4 @@
 /* eslint-disable
 /* eslint-disable
-    camelcase,
     no-unused-vars,
     no-unused-vars,
 */
 */
 // TODO: This file was created by bulk-decaffeinate.
 // TODO: This file was created by bulk-decaffeinate.
@@ -14,13 +13,13 @@ import { expect } from 'chai'
 import request from 'request'
 import request from 'request'
 import Settings from '@overleaf/settings'
 import Settings from '@overleaf/settings'
 
 
-export function getLatestContent(ol_project_id, callback) {
+export function getLatestContent(olProjectId, callback) {
   if (callback == null) {
   if (callback == null) {
     callback = function () {}
     callback = function () {}
   }
   }
   return request.get(
   return request.get(
     {
     {
-      url: `${Settings.overleaf.history.host}/projects/${ol_project_id}/latest/content`,
+      url: `${Settings.overleaf.history.host}/projects/${olProjectId}/latest/content`,
       auth: {
       auth: {
         user: Settings.overleaf.history.user,
         user: Settings.overleaf.history.user,
         pass: Settings.overleaf.history.pass,
         pass: Settings.overleaf.history.pass,

+ 0 - 1
services/project-history/test/unit/js/LockManager/LockManagerTests.js

@@ -1,5 +1,4 @@
 /* eslint-disable
 /* eslint-disable
-    camelcase,
     mocha/no-nested-tests,
     mocha/no-nested-tests,
     no-return-assign,
     no-return-assign,
     no-undef,
     no-undef,

+ 2 - 3
services/project-history/test/unit/js/UpdatesManager/UpdatesProcessorTests.js

@@ -1,5 +1,4 @@
 /* eslint-disable
 /* eslint-disable
-    camelcase,
     mocha/no-nested-tests,
     mocha/no-nested-tests,
     no-return-assign,
     no-return-assign,
     no-undef,
     no-undef,
@@ -67,8 +66,8 @@ describe('UpdatesProcessor', function () {
       redis: {
       redis: {
         lock: {
         lock: {
           key_schema: {
           key_schema: {
-            projectHistoryLock({ project_id }) {
-              return `ProjectHistoryLock:${project_id}`
+            projectHistoryLock({ project_id: projectId }) {
+              return `ProjectHistoryLock:${projectId}`
             },
             },
           },
           },
         },
         },