Fix HourlyRate display in admin area to include only relevant projects - #24697
Conversation
| projects_with_costs.each do |project| | ||
| rates[project] = rates_by_project.fetch(project, []) | ||
| project_rates = rates_by_project.fetch(project, []) | ||
| next if project_rates.empty? && usr.projects.exclude?(project) |
There was a problem hiding this comment.
Could this cause an N+1 query? usr.projects.exclude?(project) may query the db for each project. The view also checks @user.projects.include?(project). Maybe we could load the user’s projects once and reuse them in both places?
There was a problem hiding this comment.
user.projects is loaded once and is then cached, it does 1 extra query, not n+1.
There was a problem hiding this comment.
I thought it might be cached too, but doesn’t include? run an EXISTS query each time when the association hasn’t been loaded yet?
There was a problem hiding this comment.
When the association is loaded, it will not issue an EXISTS query. I explicitly added the load statement so that it is ensured that it is preloaded, even though it should already be.
There was a problem hiding this comment.
Ok, thanks for explanation.
Ticket
https://community.openproject.org/projects/OP/work_packages/OP-19843/activity
What are you trying to accomplish?
Screenshots
What approach did you choose and why?
Merge checklist