Commit 9d154542 authored by Dmytro Zaporozhets's avatar Dmytro Zaporozhets

Merge branch 'jprovazn-fix-group-preloader' into 'master'

Use gitlab_subscription in group preloader

See merge request gitlab-org/gitlab!23184
parents bedccdce 77c4fec6
---
title: Fix loading of sub-epics caused by wrong subscription check.
merge_request: 23184
author:
type: fixed
......@@ -35,6 +35,7 @@ module EE
accepts_nested_attributes_for :gitlab_subscription
scope :include_gitlab_subscription, -> { includes(:gitlab_subscription) }
scope :join_gitlab_subscription, -> { joins("LEFT OUTER JOIN gitlab_subscriptions ON gitlab_subscriptions.namespace_id=namespaces.id") }
scope :with_plan, -> { where.not(plan_id: nil) }
scope :with_shared_runners_minutes_limit, -> { where("namespaces.shared_runners_minutes_limit > 0") }
scope :with_extra_shared_runners_minutes_limit, -> { where("namespaces.extra_shared_runners_minutes_limit > 0") }
......
......@@ -32,7 +32,7 @@ module Gitlab
while current
if (plan_id = current.plan_id)
if (plan_id = current.hosted_plan_id)
hash[group.id] << plan_id
all_plan_ids << plan_id
end
......@@ -61,7 +61,8 @@ module Gitlab
Gitlab::ObjectHierarchy
.new(groups)
.base_and_ancestors
.select(:id, :parent_id, :plan_id)
.join_gitlab_subscription
.select('namespaces.id', 'namespaces.parent_id', 'gitlab_subscriptions.hosted_plan_id')
end
end
end
......@@ -14,9 +14,12 @@ describe Gitlab::GroupPlansPreloader do
end
before do
group1 = create(:group, name: 'group-1', plan_id: plan1.id)
group1 = create(:group, name: 'group-1')
create(:gitlab_subscription, namespace: group1, hosted_plan_id: plan1.id)
group2 = create(:group, name: 'group-2', plan_id: plan2.id)
create(:gitlab_subscription, namespace: group2, hosted_plan_id: plan2.id)
create(:group, name: 'group-2', plan_id: plan2.id)
create(:group, name: 'group-3', parent: group1)
end
......
......@@ -77,6 +77,24 @@ describe Namespace do
end
end
end
describe '.join_gitlab_subscription' do
subject { described_class.join_gitlab_subscription.select('gitlab_subscriptions.hosted_plan_id').first.hosted_plan_id }
context 'when there is no subscription' do
it 'returns namespace with nil subscription' do
is_expected.to be_nil
end
end
context 'when there is a subscription' do
let!(:subscription) { create(:gitlab_subscription, namespace: namespace, hosted_plan_id: gold_plan.id) }
it 'returns namespace with subscription set' do
is_expected.to eq(gold_plan.id)
end
end
end
end
context 'validation' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment