Add latest changes from gitlab-org/gitlab@master

This commit is contained in:
GitLab Bot 2022-10-16 21:08:47 +00:00
parent 1c29577b90
commit 3d5d885a6a
2 changed files with 4 additions and 5 deletions

View File

@ -10,7 +10,7 @@ module Resolvers
authorize!(object)
BatchLoader::GraphQL.for(object.id).batch(cache: false) do |ids, loader, args|
labels = Label.for_targets(ids, object.class.name).group_by(&:target_id)
labels = Label.for_targets(object.class.id_in(ids)).group_by(&:target_id)
ids.each do |id|
loader.call(id, labels[id] || [])

View File

@ -60,11 +60,10 @@ class Label < ApplicationRecord
.distinct
}
scope :for_targets, ->(target_ids, targets_type) do
scope :for_targets, ->(target_relation) do
joins(:label_links)
.where(label_links: { target_id: target_ids })
.where(label_links: { target_type: targets_type })
.select("labels.*, target_id")
.merge(LabelLink.where(target: target_relation))
.select(arel_table[Arel.star], LabelLink.arel_table[:target_id])
.with_preloaded_container
end