-
-
Notifications
You must be signed in to change notification settings - Fork 484
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
fix n+1 queries issue in supervisors#index and supervisors#datatable #5947
Conversation
…_controller#datatable
@@ -12,7 +12,10 @@ class SupervisorsController < ApplicationController | |||
|
|||
def index | |||
authorize Supervisor | |||
@supervisors = policy_scope(current_organization.supervisors) | |||
@supervisors = policy_scope(current_organization.supervisors).includes( |
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.
Do you know what this policy scope is adding to the query? could we move the includes? or is it reused elsewhere where the preloading isn't needed?
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'm not sure about the policy_scope. i did not see other uses of @supervisors
atm. is there a place you think itd be better to move it to?
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'm not making a suggestion I was just posing another angle that you might consider, since it might be less code duplication.
You could move the includes bits to https://github.com/rubyforgood/casa/blob/main/app/policies/supervisor_policy.rb and have something like
class Scope < ApplicationPolicy::Scope |
…ml.erb formatting fixes
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.
LGTM! Thanks! This was a 3 year old N+1 issue I believe :)
What github issue is this PR for, if any?
Resolves #5890
Resolve #5891
What changed, and why?
Fixes the N+1 issues for the Supervisors#index and Supervisors#datatable. Does this by preloading any record associations that are used later on.
How is this tested? (please write tests!) 💖💪
Screenshots please :)
supervisors#index
beforesupervisors#index
aftersupervisors#datatable
beforesupervisors#datatable
after