Commit f70e02af authored by Shinya Maeda's avatar Shinya Maeda

Merge branch 'only_log_inefficient_updated_at_query' into 'master'

Only log inefficient query error

See merge request gitlab-org/gitlab!80456
parents 2c63e7c8 864d99ad
......@@ -49,6 +49,10 @@ class DeploymentsFinder
private
def raise_for_inefficient_updated_at_query?
params.fetch(:raise_for_inefficient_updated_at_query, Rails.env.development? || Rails.env.test?)
end
def validate!
if filter_by_updated_at? && filter_by_finished_at?
raise InefficientQueryError, 'Both `updated_at` filter and `finished_at` filter can not be specified'
......@@ -57,9 +61,11 @@ class DeploymentsFinder
# Currently, the inefficient parameters are allowed in order to avoid breaking changes in Deployment API.
# We'll switch to a hard error in https://gitlab.com/gitlab-org/gitlab/-/issues/328500.
if (filter_by_updated_at? && !order_by_updated_at?) || (!filter_by_updated_at? && order_by_updated_at?)
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(
InefficientQueryError.new('`updated_at` filter and `updated_at` sorting must be paired')
)
error = InefficientQueryError.new('`updated_at` filter and `updated_at` sorting must be paired')
Gitlab::ErrorTracking.log_exception(error)
raise error if raise_for_inefficient_updated_at_query?
end
if (filter_by_finished_at? && !order_by_finished_at?) || (!filter_by_finished_at? && order_by_finished_at?)
......
......@@ -222,11 +222,7 @@ RSpec.describe DeploymentsFinder do
end
describe 'enforce sorting to `updated_at` sorting' do
let(:params) { { **base_params, updated_before: 1.day.ago, order_by: 'id', sort: 'asc' } }
before do
allow(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception)
end
let(:params) { { **base_params, updated_before: 1.day.ago, order_by: 'id', sort: 'asc', raise_for_inefficient_updated_at_query: false } }
it 'sorts by only one column' do
expect(subject.order_values.size).to eq(2)
......
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