Commit d7ed9fff authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '212666-take-user-min-and-max-ids-only-one-time-for-all-counters' into 'master'

Take User min and max IDs only one time for all counters

Closes #212666

See merge request gitlab-org/gitlab!33168
parents 3a5a7266 5e63f450
......@@ -256,15 +256,15 @@ module EE
projects_imported_from_github: distinct_count(::Project.github_imported.where(time_period), :creator_id),
projects_with_repositories_enabled: distinct_count(::Project.with_repositories_enabled.where(time_period),
:creator_id,
start: ::User.minimum(:id),
finish: ::User.maximum(:id)),
protected_branches: distinct_count(::Project.with_protected_branches.where(time_period), :creator_id, start: ::User.minimum(:id), finish: ::User.maximum(:id)),
start: user_minimum_id,
finish: user_maximum_id),
protected_branches: distinct_count(::Project.with_protected_branches.where(time_period), :creator_id, start: user_minimum_id, finish: user_maximum_id),
remote_mirrors: distinct_count(::Project.with_remote_mirrors.where(time_period), :creator_id),
snippets: distinct_count(::Snippet.where(time_period), :author_id),
suggestions: distinct_count(::Note.with_suggestions.where(time_period),
:author_id,
start: ::User.minimum(:id),
finish: ::User.maximum(:id))
start: user_minimum_id,
finish: user_maximum_id)
}
end
......@@ -377,8 +377,8 @@ module EE
private
def distinct_count_service_desk_enabled_projects(time_period)
project_creator_id_start = ::User.minimum(:id)
project_creator_id_finish = ::User.maximum(:id)
project_creator_id_start = user_minimum_id
project_creator_id_finish = user_maximum_id
distinct_count(::Project.service_desk_enabled.where(time_period), :creator_id, start: project_creator_id_start, finish: project_creator_id_finish)
end
......
......@@ -17,6 +17,7 @@ module Gitlab
class << self
include Gitlab::Utils::UsageData
include Gitlab::Utils::StrongMemoize
def data(force_refresh: false)
Rails.cache.fetch('usage_data', force: force_refresh, expires_in: 2.weeks) do
......@@ -25,6 +26,8 @@ module Gitlab
end
def uncached_data
clear_memoized_limits
license_usage_data
.merge(system_usage_data)
.merge(features_usage_data)
......@@ -438,6 +441,25 @@ module Gitlab
def default_time_period
{ created_at: 28.days.ago..Time.current }
end
private
def user_minimum_id
strong_memoize(:user_minimum_id) do
::User.minimum(:id)
end
end
def user_maximum_id
strong_memoize(:user_maximum_id) do
::User.maximum(:id)
end
end
def clear_memoized_limits
clear_memoization(:user_minimum_id)
clear_memoization(:user_maximum_id)
end
end
end
end
......
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