Commit 91cb510d authored by Alper Akgun's avatar Alper Akgun Committed by Bob Van Landuyt

Improve DistinctCountByLargeForeignKey cop

- Removes UsageData/DistinctCountByLargeForeignKey for some metrics
- Puts allowed foreign keys in alphabetical order Improves
- Cop to accept both string and symbol arguments
parent 06ad533c
......@@ -815,11 +815,9 @@ module Gitlab
end
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable UsageData/DistinctCountByLargeForeignKey
def cluster_applications_user_distinct_count(applications, time_period)
distinct_count(applications.where(time_period).available.joins(:cluster), 'clusters.user_id')
end
# rubocop: enable UsageData/DistinctCountByLargeForeignKey
def clusters_user_distinct_count(clusters, time_period)
distinct_count(clusters.where(time_period), :user_id)
......
......@@ -31,11 +31,11 @@ module RuboCop
private
def allowed_foreign_key?(key)
[:sym, :str].include?(key.type) && allowed_foreign_keys.include?(key.value.to_sym)
[:sym, :str].include?(key.type) && allowed_foreign_keys.include?(key.value.to_s)
end
def allowed_foreign_keys
cop_config['AllowedForeignKeys'] || []
(cop_config['AllowedForeignKeys'] || []).map(&:to_s)
end
end
end
......
......@@ -38,12 +38,13 @@ UsageData/DistinctCountByLargeForeignKey:
- 'lib/gitlab/usage_data.rb'
- 'ee/lib/ee/gitlab/usage_data.rb'
AllowedForeignKeys:
- :user_id
- :author_id
- :creator_id
- :owner_id
- :project_id
- :issue_id
- :merge_request_id
- :merge_requests.target_project_id
- :agent_id
- 'agent_id'
- 'author_id'
- 'clusters.user_id'
- 'creator_id'
- 'issue_id'
- 'merge_request_id'
- 'merge_requests.target_project_id'
- 'owner_id'
- 'project_id'
- 'user_id'
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