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

Camel case variables in project-history

GitOrigin-RevId: 299245883b44366911ee43ee7e644a7bfa3d8319
This commit is contained in:
Eric Mc Sween 2023-03-20 09:41:11 -04:00 committed by Copybot
parent 122d2310e6
commit 5fe98bf0fd
12 changed files with 65 additions and 78 deletions

View file

@ -1,5 +1,4 @@
/* eslint-disable
camelcase,
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
@ -15,12 +14,12 @@ import logger from '@overleaf/logger'
import Settings from '@overleaf/settings'
import OError from '@overleaf/o-error'
export function getDocument(project_id, doc_id, callback) {
export function getDocument(projectId, docId, callback) {
if (callback == null) {
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) {
if (error != null) {
return callback(OError.tag(error))
@ -33,33 +32,33 @@ export function getDocument(project_id, doc_id, callback) {
return callback(error)
}
logger.debug(
{ project_id, doc_id, version: body.version },
{ projectId, docId, version: body.version },
'got doc from document updater'
)
return callback(null, body.lines.join('\n'), body.version)
} else {
error = new OError(
`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)
}
})
}
export function setDocument(project_id, doc_id, content, user_id, callback) {
export function setDocument(projectId, docId, content, userId, callback) {
if (callback == null) {
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(
{
url,
json: {
lines: content.split('\n'),
source: 'restore',
user_id,
user_id: userId,
undoing: true,
},
},
@ -72,7 +71,7 @@ export function setDocument(project_id, doc_id, content, user_id, callback) {
} else {
error = new OError(
`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)
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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