diff options
author | Stan Hu <stanhu@gmail.com> | 2019-02-26 22:30:43 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-02-26 23:44:28 +0300 |
commit | ebb284c0dc59e2fd5bc76921609b60034f000c53 (patch) | |
tree | a80846427413ae82868fc391ecda6edab846eb28 /app | |
parent | 3395eacb57285424b7b8d49bdf836f638af31e8c (diff) |
Remove N+1 query for tags in /admin/runners page
As discussed in https://github.com/mbleigh/acts-as-taggable-on/issues/91,
we can avoid N+1 queries if we use `tags` instead of `tag_list`.
Seen while reviewing
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/19740.
Diffstat (limited to 'app')
-rw-r--r-- | app/finders/admin/runners_finder.rb | 2 | ||||
-rw-r--r-- | app/models/ci/runner.rb | 1 | ||||
-rw-r--r-- | app/views/admin/runners/_runner.html.haml | 2 |
3 files changed, 3 insertions, 2 deletions
diff --git a/app/finders/admin/runners_finder.rb b/app/finders/admin/runners_finder.rb index fbb1cfc5c66..8d936b8121c 100644 --- a/app/finders/admin/runners_finder.rb +++ b/app/finders/admin/runners_finder.rb @@ -14,7 +14,7 @@ class Admin::RunnersFinder < UnionFinder sort! paginate! - @runners + @runners.with_tags end def sort_key diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb index 5aae31de6e2..d82e11bbb89 100644 --- a/app/models/ci/runner.rb +++ b/app/models/ci/runner.rb @@ -97,6 +97,7 @@ module Ci scope :order_contacted_at_asc, -> { order(contacted_at: :asc) } scope :order_created_at_desc, -> { order(created_at: :desc) } + scope :with_tags, -> { preload(:tags) } validate :tag_constraints validates :access_level, presence: true diff --git a/app/views/admin/runners/_runner.html.haml b/app/views/admin/runners/_runner.html.haml index 4641986cb56..ecf2b1d60ba 100644 --- a/app/views/admin/runners/_runner.html.haml +++ b/app/views/admin/runners/_runner.html.haml @@ -49,7 +49,7 @@ .table-section.section-10.section-wrap .table-mobile-header{ role: 'rowheader' }= _('Tags') .table-mobile-content - - runner.tag_list.sort.each do |tag| + - runner.tags.map(&:name).sort.each do |tag| %span.badge.badge-primary = tag |