mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Decaf cleanup: unnecessary returns
This commit is contained in:
parent
819aa378d9
commit
2bff83137c
1 changed files with 80 additions and 103 deletions
|
@ -7,7 +7,6 @@
|
||||||
// Fix any style issues and re-enable lint.
|
// Fix any style issues and re-enable lint.
|
||||||
/*
|
/*
|
||||||
* decaffeinate suggestions:
|
* decaffeinate suggestions:
|
||||||
* DS102: Remove unnecessary code created because of implicit returns
|
|
||||||
* DS207: Consider shorter variations of null checks
|
* DS207: Consider shorter variations of null checks
|
||||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||||
*/
|
*/
|
||||||
|
@ -29,13 +28,10 @@ module.exports = ProjectManager = {
|
||||||
const timer = new Metrics.Timer('projectManager.flushProjectWithLocks')
|
const timer = new Metrics.Timer('projectManager.flushProjectWithLocks')
|
||||||
const callback = function (...args) {
|
const callback = function (...args) {
|
||||||
timer.done()
|
timer.done()
|
||||||
return _callback(...args)
|
_callback(...args)
|
||||||
}
|
}
|
||||||
|
|
||||||
return RedisManager.getDocIdsInProject(project_id, function (
|
RedisManager.getDocIdsInProject(project_id, function (error, doc_ids) {
|
||||||
error,
|
|
||||||
doc_ids
|
|
||||||
) {
|
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
return callback(error)
|
return callback(error)
|
||||||
}
|
}
|
||||||
|
@ -53,16 +49,16 @@ module.exports = ProjectManager = {
|
||||||
{ err: error, project_id, doc_id },
|
{ err: error, project_id, doc_id },
|
||||||
'found deleted doc when flushing'
|
'found deleted doc when flushing'
|
||||||
)
|
)
|
||||||
return callback()
|
callback()
|
||||||
} else if (error != null) {
|
} else if (error != null) {
|
||||||
logger.error(
|
logger.error(
|
||||||
{ err: error, project_id, doc_id },
|
{ err: error, project_id, doc_id },
|
||||||
'error flushing doc'
|
'error flushing doc'
|
||||||
)
|
)
|
||||||
errors.push(error)
|
errors.push(error)
|
||||||
return callback()
|
callback()
|
||||||
} else {
|
} else {
|
||||||
return callback()
|
callback()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -70,13 +66,11 @@ module.exports = ProjectManager = {
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.log({ project_id, doc_ids }, 'flushing docs')
|
logger.log({ project_id, doc_ids }, 'flushing docs')
|
||||||
return async.series(jobs, function () {
|
async.series(jobs, function () {
|
||||||
if (errors.length > 0) {
|
if (errors.length > 0) {
|
||||||
return callback(
|
callback(new Error('Errors flushing docs. See log for details'))
|
||||||
new Error('Errors flushing docs. See log for details')
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
return callback(null)
|
callback(null)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -91,13 +85,10 @@ module.exports = ProjectManager = {
|
||||||
)
|
)
|
||||||
const callback = function (...args) {
|
const callback = function (...args) {
|
||||||
timer.done()
|
timer.done()
|
||||||
return _callback(...args)
|
_callback(...args)
|
||||||
}
|
}
|
||||||
|
|
||||||
return RedisManager.getDocIdsInProject(project_id, function (
|
RedisManager.getDocIdsInProject(project_id, function (error, doc_ids) {
|
||||||
error,
|
|
||||||
doc_ids
|
|
||||||
) {
|
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
return callback(error)
|
return callback(error)
|
||||||
}
|
}
|
||||||
|
@ -118,14 +109,14 @@ module.exports = ProjectManager = {
|
||||||
)
|
)
|
||||||
errors.push(error)
|
errors.push(error)
|
||||||
}
|
}
|
||||||
return callback()
|
callback()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
))(doc_id)
|
))(doc_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.log({ project_id, doc_ids }, 'deleting docs')
|
logger.log({ project_id, doc_ids }, 'deleting docs')
|
||||||
return async.series(jobs, () =>
|
async.series(jobs, () =>
|
||||||
// When deleting the project here we want to ensure that project
|
// When deleting the project here we want to ensure that project
|
||||||
// history is completely flushed because the project may be
|
// history is completely flushed because the project may be
|
||||||
// deleted in web after this call completes, and so further
|
// deleted in web after this call completes, and so further
|
||||||
|
@ -134,13 +125,11 @@ module.exports = ProjectManager = {
|
||||||
error
|
error
|
||||||
) {
|
) {
|
||||||
if (errors.length > 0) {
|
if (errors.length > 0) {
|
||||||
return callback(
|
callback(new Error('Errors deleting docs. See log for details'))
|
||||||
new Error('Errors deleting docs. See log for details')
|
|
||||||
)
|
|
||||||
} else if (error != null) {
|
} else if (error != null) {
|
||||||
return callback(error)
|
callback(error)
|
||||||
} else {
|
} else {
|
||||||
return callback(null)
|
callback(null)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
@ -151,9 +140,7 @@ module.exports = ProjectManager = {
|
||||||
if (callback == null) {
|
if (callback == null) {
|
||||||
callback = function (error) {}
|
callback = function (error) {}
|
||||||
}
|
}
|
||||||
return RedisManager.queueFlushAndDeleteProject(project_id, function (
|
RedisManager.queueFlushAndDeleteProject(project_id, function (error) {
|
||||||
error
|
|
||||||
) {
|
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
logger.error(
|
logger.error(
|
||||||
{ project_id, error },
|
{ project_id, error },
|
||||||
|
@ -162,7 +149,7 @@ module.exports = ProjectManager = {
|
||||||
return callback(error)
|
return callback(error)
|
||||||
}
|
}
|
||||||
Metrics.inc('queued-delete')
|
Metrics.inc('queued-delete')
|
||||||
return callback()
|
callback()
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -170,24 +157,18 @@ module.exports = ProjectManager = {
|
||||||
if (callback == null) {
|
if (callback == null) {
|
||||||
callback = function (error) {}
|
callback = function (error) {}
|
||||||
}
|
}
|
||||||
return RedisManager.getDocIdsInProject(project_id, function (
|
RedisManager.getDocIdsInProject(project_id, function (error, doc_ids) {
|
||||||
error,
|
|
||||||
doc_ids
|
|
||||||
) {
|
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
return callback(error)
|
return callback(error)
|
||||||
}
|
}
|
||||||
if (!(doc_ids != null ? doc_ids.length : undefined)) {
|
if (!(doc_ids != null ? doc_ids.length : undefined)) {
|
||||||
return callback(null, [])
|
return callback(null, [])
|
||||||
}
|
}
|
||||||
return RedisManager.getDocTimestamps(doc_ids, function (
|
RedisManager.getDocTimestamps(doc_ids, function (error, timestamps) {
|
||||||
error,
|
|
||||||
timestamps
|
|
||||||
) {
|
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
return callback(error)
|
return callback(error)
|
||||||
}
|
}
|
||||||
return callback(null, timestamps)
|
callback(null, timestamps)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
@ -209,13 +190,13 @@ module.exports = ProjectManager = {
|
||||||
)
|
)
|
||||||
const callback = function (...args) {
|
const callback = function (...args) {
|
||||||
timer.done()
|
timer.done()
|
||||||
return _callback(...args)
|
_callback(...args)
|
||||||
}
|
}
|
||||||
|
|
||||||
return RedisManager.checkOrSetProjectState(
|
RedisManager.checkOrSetProjectState(project_id, projectStateHash, function (
|
||||||
project_id,
|
error,
|
||||||
projectStateHash,
|
projectStateChanged
|
||||||
function (error, projectStateChanged) {
|
) {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
logger.error(
|
logger.error(
|
||||||
{ err: error, project_id },
|
{ err: error, project_id },
|
||||||
|
@ -230,10 +211,7 @@ module.exports = ProjectManager = {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// project structure hasn't changed, return doc content from redis
|
// project structure hasn't changed, return doc content from redis
|
||||||
return RedisManager.getDocIdsInProject(project_id, function (
|
RedisManager.getDocIdsInProject(project_id, function (error, doc_ids) {
|
||||||
error,
|
|
||||||
doc_ids
|
|
||||||
) {
|
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
logger.error(
|
logger.error(
|
||||||
{ err: error, project_id },
|
{ err: error, project_id },
|
||||||
|
@ -259,27 +237,26 @@ module.exports = ProjectManager = {
|
||||||
return cb(err)
|
return cb(err)
|
||||||
}
|
}
|
||||||
const doc = { _id: doc_id, lines, v: version } // create a doc object to return
|
const doc = { _id: doc_id, lines, v: version } // create a doc object to return
|
||||||
return cb(null, doc)
|
cb(null, doc)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
))(doc_id)
|
))(doc_id)
|
||||||
}
|
}
|
||||||
return async.series(jobs, function (error, docs) {
|
async.series(jobs, function (error, docs) {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
return callback(error)
|
return callback(error)
|
||||||
}
|
}
|
||||||
return callback(null, docs)
|
callback(null, docs)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
|
|
||||||
clearProjectState(project_id, callback) {
|
clearProjectState(project_id, callback) {
|
||||||
if (callback == null) {
|
if (callback == null) {
|
||||||
callback = function (error) {}
|
callback = function (error) {}
|
||||||
}
|
}
|
||||||
return RedisManager.clearProjectState(project_id, callback)
|
RedisManager.clearProjectState(project_id, callback)
|
||||||
},
|
},
|
||||||
|
|
||||||
updateProjectWithLocks(
|
updateProjectWithLocks(
|
||||||
|
@ -297,7 +274,7 @@ module.exports = ProjectManager = {
|
||||||
const timer = new Metrics.Timer('projectManager.updateProject')
|
const timer = new Metrics.Timer('projectManager.updateProject')
|
||||||
const callback = function (...args) {
|
const callback = function (...args) {
|
||||||
timer.done()
|
timer.done()
|
||||||
return _callback(...args)
|
_callback(...args)
|
||||||
}
|
}
|
||||||
|
|
||||||
const project_version = version
|
const project_version = version
|
||||||
|
@ -309,7 +286,7 @@ module.exports = ProjectManager = {
|
||||||
const doc_id = projectUpdate.id
|
const doc_id = projectUpdate.id
|
||||||
projectUpdate.version = `${project_version}.${project_subversion++}`
|
projectUpdate.version = `${project_version}.${project_subversion++}`
|
||||||
if (projectUpdate.docLines != null) {
|
if (projectUpdate.docLines != null) {
|
||||||
return ProjectHistoryRedisManager.queueAddEntity(
|
ProjectHistoryRedisManager.queueAddEntity(
|
||||||
project_id,
|
project_id,
|
||||||
projectHistoryId,
|
projectHistoryId,
|
||||||
'doc',
|
'doc',
|
||||||
|
@ -318,11 +295,11 @@ module.exports = ProjectManager = {
|
||||||
projectUpdate,
|
projectUpdate,
|
||||||
function (error, count) {
|
function (error, count) {
|
||||||
project_ops_length = count
|
project_ops_length = count
|
||||||
return cb(error)
|
cb(error)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
return DocumentManager.renameDocWithLock(
|
DocumentManager.renameDocWithLock(
|
||||||
project_id,
|
project_id,
|
||||||
doc_id,
|
doc_id,
|
||||||
user_id,
|
user_id,
|
||||||
|
@ -330,7 +307,7 @@ module.exports = ProjectManager = {
|
||||||
projectHistoryId,
|
projectHistoryId,
|
||||||
function (error, count) {
|
function (error, count) {
|
||||||
project_ops_length = count
|
project_ops_length = count
|
||||||
return cb(error)
|
cb(error)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -340,7 +317,7 @@ module.exports = ProjectManager = {
|
||||||
const file_id = projectUpdate.id
|
const file_id = projectUpdate.id
|
||||||
projectUpdate.version = `${project_version}.${project_subversion++}`
|
projectUpdate.version = `${project_version}.${project_subversion++}`
|
||||||
if (projectUpdate.url != null) {
|
if (projectUpdate.url != null) {
|
||||||
return ProjectHistoryRedisManager.queueAddEntity(
|
ProjectHistoryRedisManager.queueAddEntity(
|
||||||
project_id,
|
project_id,
|
||||||
projectHistoryId,
|
projectHistoryId,
|
||||||
'file',
|
'file',
|
||||||
|
@ -349,11 +326,11 @@ module.exports = ProjectManager = {
|
||||||
projectUpdate,
|
projectUpdate,
|
||||||
function (error, count) {
|
function (error, count) {
|
||||||
project_ops_length = count
|
project_ops_length = count
|
||||||
return cb(error)
|
cb(error)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
return ProjectHistoryRedisManager.queueRenameEntity(
|
ProjectHistoryRedisManager.queueRenameEntity(
|
||||||
project_id,
|
project_id,
|
||||||
projectHistoryId,
|
projectHistoryId,
|
||||||
'file',
|
'file',
|
||||||
|
@ -362,17 +339,17 @@ module.exports = ProjectManager = {
|
||||||
projectUpdate,
|
projectUpdate,
|
||||||
function (error, count) {
|
function (error, count) {
|
||||||
project_ops_length = count
|
project_ops_length = count
|
||||||
return cb(error)
|
cb(error)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return async.eachSeries(docUpdates, handleDocUpdate, function (error) {
|
async.eachSeries(docUpdates, handleDocUpdate, function (error) {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
return callback(error)
|
return callback(error)
|
||||||
}
|
}
|
||||||
return async.eachSeries(fileUpdates, handleFileUpdate, function (error) {
|
async.eachSeries(fileUpdates, handleFileUpdate, function (error) {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
return callback(error)
|
return callback(error)
|
||||||
}
|
}
|
||||||
|
@ -385,7 +362,7 @@ module.exports = ProjectManager = {
|
||||||
) {
|
) {
|
||||||
HistoryManager.flushProjectChangesAsync(project_id)
|
HistoryManager.flushProjectChangesAsync(project_id)
|
||||||
}
|
}
|
||||||
return callback()
|
callback()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue