diff options
author | Stan Hu <stanhu@gmail.com> | 2019-09-03 16:23:39 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-09-03 16:23:39 +0300 |
commit | 8326e84ed02c42d4e2fe3504ed0e4e4d049429bb (patch) | |
tree | 153a67422e936b2416346e9cb2663b4b70d1405b /app | |
parent | 264b0878e2d7a8f2c355c3159b0fbfa7ea34b8ac (diff) | |
parent | 53801b1206ff9e165b30117e3c3bcf543db7ad2c (diff) |
Merge branch 'ab-routable-nplus1' into 'master'
Preload routes information in Routable
See merge request gitlab-org/gitlab-ce!32352
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/admin/groups_controller.rb | 6 | ||||
-rw-r--r-- | app/models/concerns/routable.rb | 4 |
2 files changed, 7 insertions, 3 deletions
diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index 6317fa7c8d1..32a36da56fe 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -14,7 +14,11 @@ class Admin::GroupsController < Admin::ApplicationController # rubocop: disable CodeReuse/ActiveRecord def show - @group = Group.with_statistics.joins(:route).group('routes.path').find_by_full_path(params[:id]) + # Group.with_statistics doesn't behave nicely when including other relations. + # Group.find_by_full_path includes the routes relation to avoid a common N+1 + # (at the expense of this action: there are two queries here to find and retrieve + # the Group with statistics). + @group = Group.with_statistics.find(group&.id) @members = present_members( @group.members.order("access_level DESC").page(params[:members_page])) @requesters = present_members( diff --git a/app/models/concerns/routable.rb b/app/models/concerns/routable.rb index 3a486632800..07d22641a0a 100644 --- a/app/models/concerns/routable.rb +++ b/app/models/concerns/routable.rb @@ -38,7 +38,7 @@ module Routable if Feature.enabled?(:routable_two_step_lookup) # Case sensitive match first (it's cheaper and the usual case) # If we didn't have an exact match, we perform a case insensitive search - found = joins(:route).find_by(routes: { path: path }) || where_full_path_in([path]).take + found = includes(:route).find_by(routes: { path: path }) || where_full_path_in([path]).take else order_sql = Arel.sql("(CASE WHEN routes.path = #{connection.quote(path)} THEN 0 ELSE 1 END)") found = where_full_path_in([path]).reorder(order_sql).take @@ -67,7 +67,7 @@ module Routable "(LOWER(routes.path) = LOWER(#{connection.quote(path)}))" end - joins(:route).where(wheres.join(' OR ')) + includes(:route).where(wheres.join(' OR ')).references(:routes) end # Temporary instrumentation of method calls |