diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-08 00:09:00 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-08 00:09:00 +0300 |
commit | 9a4d2a38dc79330beb9f8ffb44d88a1b8f699d75 (patch) | |
tree | 482027505bc0ba0a857f1aaa6a9653e4f9ddd5b1 /spec/support/matchers | |
parent | 5cda8c8a420399ca9687c4a981fefd50ce5a1fdd (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support/matchers')
-rw-r--r-- | spec/support/matchers/exceed_query_limit.rb | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/spec/support/matchers/exceed_query_limit.rb b/spec/support/matchers/exceed_query_limit.rb index 23f43e05a10..e767990d351 100644 --- a/spec/support/matchers/exceed_query_limit.rb +++ b/spec/support/matchers/exceed_query_limit.rb @@ -121,13 +121,27 @@ module ExceedQueryLimitHelpers end end - unless @show_common_queries - combined_counts = combined_counts.transform_values do |suffs| - suffs.reject { |_k, counts| counts.first == counts.second } - end - end + reject_groups_with_matching_counts(combined_counts) + end + + def reject_groups_with_matching_counts(combined_counts) + return combined_counts if @show_common_queries + + combined_counts + .transform_values { select_suffixes_with_diffs(_1) } + .reject { |_prefix, suffs| suffs.empty? } + end + + def select_suffixes_with_diffs(suffs) + # reject when count in LHS is the same as count in RHS + suffs = suffs.reject { |_k, counts| counts.first == counts.second } + + # Reject common case of N queries on LHS and N on right, but with different parameters + # accepts as equivalent if a == [0, 1] and b == [1, 0], for example + keys = suffs.keys + return {} if keys.size == 2 && suffs[keys.first] == suffs[keys.second].reverse - combined_counts.reject { |_prefix, suffs| suffs.empty? } + suffs end def diff_query_group_message(query, suffixes) @@ -141,7 +155,7 @@ module ExceedQueryLimitHelpers def log_message if expected.is_a?(ActiveRecord::QueryRecorder) diff_counts = diff_query_counts(count_queries(expected), count_queries(@recorder)) - sections = diff_counts.map { |q, suffixes| diff_query_group_message(q, suffixes) } + sections = diff_counts.filter_map { |q, suffixes| diff_query_group_message(q, suffixes) } <<~MSG Query Diff: |