-
-
Notifications
You must be signed in to change notification settings - Fork 366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add null check when job is undefined #139
Conversation
@@ -70,7 +70,7 @@ module.exports = async function getDataForQeues({ queues, query = {} }) { | |||
return { | |||
name, | |||
counts, | |||
jobs: jobs.map(formatJob), | |||
jobs: jobs.filter((job) => !!job).map(formatJob), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A reduce
instead of a filter
-> map
would reduce the iteration count by up to 2x 🙂
I'd recommend going with that instead for this case!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return {
name,
counts,
jobs: jobs
.reduce((result, job) => {
if (job) {
result.push(formatJob(job))
}
return result
}, [])
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't agree with you, this consumes 2x memory, it is better to use filter & map as it is more declarative
To avoid this error for now you can remove |
This fixes a case where bull returns
null
for a job. I am not sure why bull does that but this PR adds a null check to prevent the app from crashingfixes #43