Skip to content
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

Merged
merged 1 commit into from
Jan 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion routes/getDataForQeues.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Copy link
Contributor

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!

Copy link

@robman87 robman87 Nov 25, 2020

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
        }, [])
    }

Copy link
Owner

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

}
}),
)
Expand Down