Commit 51b54a9e authored by alinamihaila's avatar alinamihaila

Take user minimum and maximum one time

  * Use strong_memoize
  * Move User.minimum and User.maximum on private methods
  * Adjust counters :start, :end to use new methods
parent 9149d54a
...@@ -256,15 +256,15 @@ module EE ...@@ -256,15 +256,15 @@ module EE
projects_imported_from_github: distinct_count(::Project.github_imported.where(time_period), :creator_id), 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), projects_with_repositories_enabled: distinct_count(::Project.with_repositories_enabled.where(time_period),
:creator_id, :creator_id,
start: ::User.minimum(:id), start: user_minimum,
finish: ::User.maximum(:id)), finish: user_maximum),
protected_branches: distinct_count(::Project.with_protected_branches.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, finish: user_maximum),
remote_mirrors: distinct_count(::Project.with_remote_mirrors.where(time_period), :creator_id), remote_mirrors: distinct_count(::Project.with_remote_mirrors.where(time_period), :creator_id),
snippets: distinct_count(::Snippet.where(time_period), :author_id), snippets: distinct_count(::Snippet.where(time_period), :author_id),
suggestions: distinct_count(::Note.with_suggestions.where(time_period), suggestions: distinct_count(::Note.with_suggestions.where(time_period),
:author_id, :author_id,
start: ::User.minimum(:id), start: user_minimum,
finish: ::User.maximum(:id)) finish: user_maximum)
} }
end end
...@@ -377,8 +377,8 @@ module EE ...@@ -377,8 +377,8 @@ module EE
private private
def distinct_count_service_desk_enabled_projects(time_period) def distinct_count_service_desk_enabled_projects(time_period)
project_creator_id_start = ::User.minimum(:id) project_creator_id_start = user_minimum
project_creator_id_finish = ::User.maximum(:id) project_creator_id_finish = user_maximum
distinct_count(::Project.service_desk_enabled.where(time_period), :creator_id, start: project_creator_id_start, finish: project_creator_id_finish) distinct_count(::Project.service_desk_enabled.where(time_period), :creator_id, start: project_creator_id_start, finish: project_creator_id_finish)
end end
......
...@@ -17,6 +17,7 @@ module Gitlab ...@@ -17,6 +17,7 @@ module Gitlab
class << self class << self
include Gitlab::Utils::UsageData include Gitlab::Utils::UsageData
include Gitlab::Utils::StrongMemoize
def data(force_refresh: false) def data(force_refresh: false)
Rails.cache.fetch('usage_data', force: force_refresh, expires_in: 2.weeks) do Rails.cache.fetch('usage_data', force: force_refresh, expires_in: 2.weeks) do
...@@ -25,6 +26,8 @@ module Gitlab ...@@ -25,6 +26,8 @@ module Gitlab
end end
def uncached_data def uncached_data
clear_memoized_limits
license_usage_data license_usage_data
.merge(system_usage_data) .merge(system_usage_data)
.merge(features_usage_data) .merge(features_usage_data)
...@@ -435,8 +438,28 @@ module Gitlab ...@@ -435,8 +438,28 @@ module Gitlab
end end
end end
<<<<<<< HEAD
def default_time_period def default_time_period
{ created_at: 28.days.ago..Time.current } { created_at: 28.days.ago..Time.current }
=======
private
def user_minimum
strong_memoize :user_minimum do
::User.minimum(:id)
end
end
def user_maximum
strong_memoize :user_maximum do
::User.maximum(:id)
end
end
def clear_memoized_limits
clear_memoization(:user_minimum)
clear_memoization(:user_maximum)
>>>>>>> db9759262b7... Take user minimum and maximum one time
end end
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