Merge pull request #10677 from overleaf/em-history-id-string

Represent history ids as strings instead of integers

GitOrigin-RevId: 18977195b65492836e570c571ec7e8c7e088612b
This commit is contained in:
Eric Mc Sween 2022-12-01 07:33:03 -05:00 committed by Copybot
parent 0e30718892
commit 5083060fbb
10 changed files with 26 additions and 33 deletions

View file

@ -99,7 +99,7 @@ function getDoc(projectId, docId, options = {}, _callback) {
body.version, body.version,
body.ranges, body.ranges,
body.pathname, body.pathname,
body.projectHistoryId, body.projectHistoryId?.toString(),
body.projectHistoryType body.projectHistoryType
) )
} else if (res.statusCode === 404) { } else if (res.statusCode === 404) {

View file

@ -244,10 +244,6 @@ module.exports = RedisManager = {
return callback(new Errors.NotFoundError('document not found')) return callback(new Errors.NotFoundError('document not found'))
} }
if (projectHistoryId != null) {
projectHistoryId = parseInt(projectHistoryId)
}
if (docLines && version && !pathname) { if (docLines && version && !pathname) {
metrics.inc('pathname', 1, { metrics.inc('pathname', 1, {
path: 'RedisManager.getDoc', path: 'RedisManager.getDoc',

View file

@ -106,7 +106,7 @@ describe('RedisManager', function () {
this.docId = 'doc-id-123' this.docId = 'doc-id-123'
this.project_id = 'project-id-123' this.project_id = 'project-id-123'
this.projectHistoryId = 123 this.projectHistoryId = '123'
this.callback = sinon.stub() this.callback = sinon.stub()
}) })

View file

@ -11,7 +11,7 @@ async function initializeProject() {
settings.apis.project_history.initializeHistoryForNewProjects settings.apis.project_history.initializeHistoryForNewProjects
) )
) { ) {
return return null
} }
const response = await fetch(`${settings.apis.project_history.url}/project`, { const response = await fetch(`${settings.apis.project_history.url}/project`, {
method: 'POST', method: 'POST',
@ -25,11 +25,11 @@ async function initializeProject() {
}) })
} }
const body = await response.json() const body = await response.json()
const overleafId = body && body.project && body.project.id const historyId = body && body.project && body.project.id
if (!overleafId) { if (!historyId) {
throw new OError('project-history did not provide an id', { body }) throw new OError('project-history did not provide an id', { body })
} }
return { overleaf_id: overleafId } return historyId
} }
async function flushProject(projectId) { async function flushProject(projectId) {

View file

@ -153,9 +153,11 @@ async function _createBlankProject(
await ProjectDetailsHandler.promises.validateProjectName(projectName) await ProjectDetailsHandler.promises.validateProjectName(projectName)
if (!attributes.overleaf) { if (!attributes.overleaf) {
const history = await HistoryManager.promises.initializeProject() const historyId = await HistoryManager.promises.initializeProject()
attributes.overleaf = { if (historyId != null) {
history: { id: history ? history.overleaf_id : undefined }, attributes.overleaf = {
history: { id: historyId },
}
} }
} }

View file

@ -154,16 +154,16 @@ const ProjectHistoryHandler = {
if (history_id != null) { if (history_id != null) {
return callback() return callback()
} // history already exists, success } // history already exists, success
return HistoryManager.initializeProject(function (err, history) { return HistoryManager.initializeProject(function (err, historyId) {
if (err != null) { if (err != null) {
return callback(err) return callback(err)
} }
if (!(history != null ? history.overleaf_id : undefined)) { if (historyId == null) {
return callback(new Error('failed to initialize history id')) return callback(new Error('failed to initialize history id'))
} }
return ProjectHistoryHandler.setHistoryId( return ProjectHistoryHandler.setHistoryId(
project_id, project_id,
history.overleaf_id, historyId,
function (err) { function (err) {
if (err != null) { if (err != null) {
return callback(err) return callback(err)

View file

@ -174,16 +174,11 @@ async function doUpgradeForNoneWithoutConversion(project) {
// Logic originally from ProjectHistoryHandler.ensureHistoryExistsForProject // Logic originally from ProjectHistoryHandler.ensureHistoryExistsForProject
// However sends a force resync project to project history instead // However sends a force resync project to project history instead
// of a resync request to doc-updater // of a resync request to doc-updater
const historyId = await ProjectHistoryHandler.promises.getHistoryId( let historyId = await ProjectHistoryHandler.promises.getHistoryId(projectId)
projectId if (historyId == null) {
) historyId = await HistoryManager.promises.initializeProject()
if (!historyId) { if (historyId != null) {
const history = await HistoryManager.promises.initializeProject() await ProjectHistoryHandler.promises.setHistoryId(projectId, historyId)
if (history && history.overleaf_id) {
await ProjectHistoryHandler.promises.setHistoryId(
projectId,
history.overleaf_id
)
} }
} }
await HistoryManager.promises.resyncProject(projectId, { await HistoryManager.promises.resyncProject(projectId, {

View file

@ -117,15 +117,15 @@ async function doUpgradeForNoneWithoutConversion(project) {
// Logic originally from ProjectHistoryHandler.ensureHistoryExistsForProject // Logic originally from ProjectHistoryHandler.ensureHistoryExistsForProject
// However sends a force resync project to project history instead // However sends a force resync project to project history instead
// of a resync request to doc-updater // of a resync request to doc-updater
const historyId = await ProjectHistoryHandler.promises.getHistoryId( let historyId = await ProjectHistoryHandler.promises.getHistoryId(
projectId projectId
) )
if (!historyId) { if (historyId == null) {
const history = await HistoryManager.promises.initializeProject() historyId = await HistoryManager.promises.initializeProject()
if (history && history.overleaf_id) { if (historyId != null) {
await ProjectHistoryHandler.promises.setHistoryId( await ProjectHistoryHandler.promises.setHistoryId(
projectId, projectId,
history.overleaf_id historyId
) )
} }
} }

View file

@ -74,7 +74,7 @@ describe('HistoryManager', function () {
}) })
it('should return the overleaf id', function () { it('should return the overleaf id', function () {
expect(this.result).to.deep.equal({ overleaf_id: this.overleaf_id }) expect(this.result).to.deep.equal(this.overleaf_id)
}) })
}) })

View file

@ -60,7 +60,7 @@ describe('ProjectHistoryHandler', function () {
this.newHistoryId = 123456789 this.newHistoryId = 123456789
this.HistoryManager.initializeProject = sinon this.HistoryManager.initializeProject = sinon
.stub() .stub()
.callsArgWith(0, null, { overleaf_id: this.newHistoryId }) .callsArgWith(0, null, this.newHistoryId)
this.HistoryManager.flushProject = sinon.stub().callsArg(1) this.HistoryManager.flushProject = sinon.stub().callsArg(1)
return (this.ProjectEntityUpdateHandler.resyncProjectHistory = sinon return (this.ProjectEntityUpdateHandler.resyncProjectHistory = sinon
.stub() .stub()