summaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
authorAndreas Brandl <abrandl@gitlab.com>2019-08-27 19:15:28 +0200
committerAndreas Brandl <abrandl@gitlab.com>2019-09-03 12:16:03 +0200
commit53801b1206ff9e165b30117e3c3bcf543db7ad2c (patch)
tree724b80019bb368f6f7e270209a612e32d578c756 /app/controllers
parentf15e3efba0e0523575ce61bd80396abda94b8cec (diff)
downloadgitlab-ce-53801b1206ff9e165b30117e3c3bcf543db7ad2c.tar.gz
Preload routes informationab-routable-nplus1
This fixes a high frequency N+1 issue: `RoutableActions#find_routable!` is used across many controllers to retrieve e.g. the Project or Namespace by path. The `#find_routable!` method calls `#ensure_canonical_path` which in turn retrieves `#full_path` from the given Routable. This in turn triggers a lookup on `routes`, leading to a high frequency of these queries: ```sql SELECT "routes".* FROM "routes" WHERE "routes"."source_id" = $1 AND "routes"."source_type" = $2 LIMIT $3 ``` This is unnecessary as we already join `routes` in `Routable#find_by_full_path` anyways.
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/admin/groups_controller.rb6
1 files changed, 5 insertions, 1 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(