Decaf cleanup: simplify loops

This commit is contained in:
Eric Mc Sween 2020-05-14 17:03:14 -04:00
parent 7a5a782dc7
commit 751d9ea718

View file

@ -19,15 +19,11 @@ module.exports = {
if (error) {
return callback(error)
}
const jobs = []
const errors = []
for (const docId of docIds) {
;((docId) =>
jobs.push((callback) =>
DocumentManager.flushDocIfLoadedWithLock(
projectId,
docId,
function (error) {
const jobs = docIds.map((docId) => (callback) => {
DocumentManager.flushDocIfLoadedWithLock(projectId, docId, function (
error
) {
if (error instanceof Errors.NotFoundError) {
logger.warn(
{ err: error, projectId, docId },
@ -35,19 +31,14 @@ module.exports = {
)
callback()
} else if (error) {
logger.error(
{ err: error, projectId, docId },
'error flushing doc'
)
logger.error({ err: error, projectId, docId }, 'error flushing doc')
errors.push(error)
callback()
} else {
callback()
}
}
)
))(docId)
}
})
})
logger.log({ projectId, docIds }, 'flushing docs')
async.series(jobs, function () {
@ -73,11 +64,8 @@ module.exports = {
if (error) {
return callback(error)
}
const jobs = []
const errors = []
for (const docId of docIds) {
;((docId) =>
jobs.push((callback) =>
const jobs = docIds.map((docId) => (callback) => {
DocumentManager.flushAndDeleteDocWithLock(
projectId,
docId,
@ -93,8 +81,7 @@ module.exports = {
callback()
}
)
))(docId)
}
})
logger.log({ projectId, docIds }, 'deleting docs')
async.series(jobs, () =>
@ -188,12 +175,8 @@ module.exports = {
)
return callback(error)
}
const jobs = []
for (const docId of docIds) {
;((docId) =>
jobs.push((
cb // get the doc lines from redis
) =>
// get the doc lines from redis
const jobs = docIds.map((docId) => (cb) => {
DocumentManager.getDocAndFlushIfOldWithLock(
projectId,
docId,
@ -209,8 +192,7 @@ module.exports = {
cb(null, doc)
}
)
))(docId)
}
})
async.series(jobs, function (error, docs) {
if (error) {
return callback(error)