Commit 7981c333 authored by Adam Hegyi's avatar Adam Hegyi

Fix Merge Request analytics query optimization

This change fixes the MR analytics query optimization. The optimization
was not triggered because additional arguments with null values were
passed by the frontend.
parent 427d48e1
...@@ -22,7 +22,7 @@ module Resolvers ...@@ -22,7 +22,7 @@ module Resolvers
def only_count_is_selected_with_merged_at_filter?(args) def only_count_is_selected_with_merged_at_filter?(args)
return unless lookahead return unless lookahead
argument_names = args.except(:lookahead, :sort, :merged_before, :merged_after).keys argument_names = args.compact.except(:lookahead, :sort, :merged_before, :merged_after).keys
# no extra filtering arguments are provided # no extra filtering arguments are provided
return unless argument_names.empty? return unless argument_names.empty?
...@@ -34,7 +34,7 @@ module Resolvers ...@@ -34,7 +34,7 @@ module Resolvers
# totalTimeToMerge # totalTimeToMerge
# } # }
allowed_selected_fields = [:count, :total_time_to_merge] allowed_selected_fields = [:count, :total_time_to_merge]
selected_fields = lookahead.selections.map(&:field).map(&:original_name) selected_fields = lookahead.selections.map(&:field).map(&:original_name) - [:__typename] # ignore __typename meta field
# only the allowed_selected_fields are present # only the allowed_selected_fields are present
(selected_fields - allowed_selected_fields).empty? (selected_fields - allowed_selected_fields).empty?
......
...@@ -407,10 +407,12 @@ RSpec.describe 'getting merge request listings nested in a project' do ...@@ -407,10 +407,12 @@ RSpec.describe 'getting merge request listings nested in a project' do
end end
let(:query) do let(:query) do
# Note: __typename meta field is always requested by the FE
graphql_query_for(:project, { full_path: project.full_path }, graphql_query_for(:project, { full_path: project.full_path },
<<~QUERY <<~QUERY
mergeRequests(mergedAfter: "2020-01-01", mergedBefore: "2020-01-05", first: 0) { mergeRequests(mergedAfter: "2020-01-01", mergedBefore: "2020-01-05", first: 0, sourceBranches: null, labels: null) {
count count
__typename
} }
QUERY QUERY
) )
......
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