diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /app/models/concerns/optimized_issuable_label_filter.rb | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'app/models/concerns/optimized_issuable_label_filter.rb')
-rw-r--r-- | app/models/concerns/optimized_issuable_label_filter.rb | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/app/models/concerns/optimized_issuable_label_filter.rb b/app/models/concerns/optimized_issuable_label_filter.rb index 7be4a26d4fa..82055822cfb 100644 --- a/app/models/concerns/optimized_issuable_label_filter.rb +++ b/app/models/concerns/optimized_issuable_label_filter.rb @@ -1,6 +1,15 @@ # frozen_string_literal: true module OptimizedIssuableLabelFilter + extend ActiveSupport::Concern + + prepended do + extend Gitlab::Cache::RequestCache + + # Avoid repeating label queries times when the finder is instantiated multiple times during the request. + request_cache(:find_label_ids) { [root_namespace.id, params.label_names] } + end + def by_label(items) return items unless params.labels? @@ -41,7 +50,7 @@ module OptimizedIssuableLabelFilter def issuables_with_selected_labels(items, target_model) if root_namespace - all_label_ids = find_label_ids(root_namespace) + all_label_ids = find_label_ids # Found less labels in the DB than we were searching for. Return nothing. return items.none if all_label_ids.size != params.label_names.size @@ -57,18 +66,20 @@ module OptimizedIssuableLabelFilter items end - def find_label_ids(root_namespace) - finder_params = { - include_subgroups: true, - include_ancestor_groups: true, - include_descendant_groups: true, - group: root_namespace, - title: params.label_names - } - - LabelsFinder - .new(nil, finder_params) - .execute(skip_authorization: true) + def find_label_ids + group_labels = Label + .where(project_id: nil) + .where(title: params.label_names) + .where(group_id: root_namespace.self_and_descendants.select(:id)) + + project_labels = Label + .where(group_id: nil) + .where(title: params.label_names) + .where(project_id: Project.select(:id).where(namespace_id: root_namespace.self_and_descendants.select(:id))) + + Label + .from_union([group_labels, project_labels], remove_duplicates: false) + .reorder(nil) .pluck(:title, :id) .group_by(&:first) .values |