diff options
author | Stan Hu <stanhu@gmail.com> | 2017-09-17 09:25:34 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2017-09-18 16:53:33 +0300 |
commit | 8690ca5c2857da39c8f5839b9383931ee026f559 (patch) | |
tree | 287b8d1dab66e00c0094027510bbbae4f10423ae /app | |
parent | a70c76df8fd746e5a83b305acbbc1c260955e332 (diff) |
Eliminate N+1 queries in loading discussions.json endpoint
In #37955,we see that the profile had a number of N+1 queries from repeated
access to `cross_reference_not_visible_for?`. This was optimized in previous
versions of GitLab by rendering all notes at once, counting the number of
visible references, and then using that number to check whether a system note
should be fully redacted.
There was also another N+1 query calling `ProjectTeam#member?`, which did not
take advantage of an optimization in prepare_notes_for_rendering that would
preload the maximum access level per project.
Closes #37955
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/issues_controller.rb | 4 | ||||
-rw-r--r-- | app/models/project_team.rb | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb index 8990c919ca0..42bfa4b9d4f 100644 --- a/app/controllers/projects/issues_controller.rb +++ b/app/controllers/projects/issues_controller.rb @@ -87,9 +87,9 @@ class Projects::IssuesController < Projects::ApplicationController .inc_relations_for_view .includes(:noteable) .fresh - .reject { |n| n.cross_reference_not_visible_for?(current_user) } - prepare_notes_for_rendering(notes) + notes = prepare_notes_for_rendering(notes) + notes = notes.reject { |n| n.cross_reference_not_visible_for?(current_user) } discussions = Discussion.build_collection(notes, @issue) diff --git a/app/models/project_team.rb b/app/models/project_team.rb index 09049824ff7..1d35426050e 100644 --- a/app/models/project_team.rb +++ b/app/models/project_team.rb @@ -146,7 +146,7 @@ class ProjectTeam def member?(user, min_access_level = Gitlab::Access::GUEST) return false unless user - user.authorized_project?(project, min_access_level) + max_member_access(user.id) >= min_access_level end def human_max_access(user_id) |