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 ...@@ -815,11 +815,9 @@ module Gitlab
end end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable UsageData/DistinctCountByLargeForeignKey
def cluster_applications_user_distinct_count(applications, time_period) def cluster_applications_user_distinct_count(applications, time_period)
distinct_count(applications.where(time_period).available.joins(:cluster), 'clusters.user_id') distinct_count(applications.where(time_period).available.joins(:cluster), 'clusters.user_id')
end end
# rubocop: enable UsageData/DistinctCountByLargeForeignKey
def clusters_user_distinct_count(clusters, time_period) def clusters_user_distinct_count(clusters, time_period)
distinct_count(clusters.where(time_period), :user_id) distinct_count(clusters.where(time_period), :user_id)
......
...@@ -31,11 +31,11 @@ module RuboCop ...@@ -31,11 +31,11 @@ module RuboCop
private private
def allowed_foreign_key?(key) 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 end
def allowed_foreign_keys def allowed_foreign_keys
cop_config['AllowedForeignKeys'] || [] (cop_config['AllowedForeignKeys'] || []).map(&:to_s)
end end
end end
end end
......
...@@ -38,12 +38,13 @@ UsageData/DistinctCountByLargeForeignKey: ...@@ -38,12 +38,13 @@ UsageData/DistinctCountByLargeForeignKey:
- 'lib/gitlab/usage_data.rb' - 'lib/gitlab/usage_data.rb'
- 'ee/lib/ee/gitlab/usage_data.rb' - 'ee/lib/ee/gitlab/usage_data.rb'
AllowedForeignKeys: AllowedForeignKeys:
- :user_id - 'agent_id'
- :author_id - 'author_id'
- :creator_id - 'clusters.user_id'
- :owner_id - 'creator_id'
- :project_id - 'issue_id'
- :issue_id - 'merge_request_id'
- :merge_request_id - 'merge_requests.target_project_id'
- :merge_requests.target_project_id - 'owner_id'
- :agent_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