Commit 525bb0a7 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'refactor-for-unleash-client' into 'master'

Refactor Feature Flag Scopes for_unleash_client

See merge request gitlab-org/gitlab-ee!14768
parents 29bd2927 faf04375
......@@ -25,10 +25,14 @@ module Operations
scope :enabled, -> { where(active: true) }
scope :disabled, -> { where(active: false) }
delegate :name, :description, to: :feature_flag
def self.with_name_and_description
joins(:feature_flag)
.select(FeatureFlag.arel_table[:name], FeatureFlag.arel_table[:description])
end
def self.for_unleash_client(project, environment)
select('DISTINCT ON (operations_feature_flag_scopes.feature_flag_id) operations_feature_flag_scopes.*')
.with_name_and_description
.where(feature_flag_id: project.operations_feature_flags.select(:id))
.order(:feature_flag_id)
.on_environment(environment)
......
---
title: Refactor feature flag scopes for_unleash_client
merge_request: 14768
author:
type: performance
......@@ -69,9 +69,9 @@ describe API::Unleash do
end
shared_examples_for 'support multiple environments' do
let(:client) { create(:operations_feature_flags_client, project: project) }
let(:base_headers) { { "UNLEASH-INSTANCEID" => client.token } }
let(:headers) { base_headers.merge({ "UNLEASH-APPNAME" => "test" }) }
let!(:client) { create(:operations_feature_flags_client, project: project) }
let!(:base_headers) { { "UNLEASH-INSTANCEID" => client.token } }
let!(:headers) { base_headers.merge({ "UNLEASH-APPNAME" => "test" }) }
let!(:feature_flag_1) do
create(:operations_feature_flag, name: "feature_flag_1", project: project, active: true)
......@@ -87,9 +87,11 @@ describe API::Unleash do
end
it 'does not have N+1 problem' do
recorded = ActiveRecord::QueryRecorder.new { subject }
control_count = ActiveRecord::QueryRecorder.new { get api(features_url), headers: headers }.count
expect(recorded.count).to be_within(8).of(10)
create(:operations_feature_flag, name: "feature_flag_3", project: project, active: true)
expect { get api(features_url), headers: headers }.not_to exceed_query_limit(control_count)
end
context 'when app name is staging' 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