diff options
Diffstat (limited to 'lib/gitlab/cycle_analytics')
-rw-r--r-- | lib/gitlab/cycle_analytics/usage_data.rb | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/gitlab/cycle_analytics/usage_data.rb b/lib/gitlab/cycle_analytics/usage_data.rb index acfb641aeec..e58def57e69 100644 --- a/lib/gitlab/cycle_analytics/usage_data.rb +++ b/lib/gitlab/cycle_analytics/usage_data.rb @@ -3,15 +3,32 @@ module Gitlab module CycleAnalytics class UsageData + include Gitlab::Utils::StrongMemoize PROJECTS_LIMIT = 10 - attr_reader :projects, :options + attr_reader :options def initialize - @projects = Project.sorted_by_activity.limit(PROJECTS_LIMIT) @options = { from: 7.days.ago } end + def projects + strong_memoize(:projects) do + projects = Project.where.not(last_activity_at: nil).order(last_activity_at: :desc).limit(10) + + Project.where.not(last_repository_updated_at: nil).order(last_repository_updated_at: :desc).limit(10) + + projects = projects.uniq.sort_by do |project| + [project.last_activity_at, project.last_repository_updated_at].min + end + + if projects.size < 10 + projects.concat(Project.where(last_activity_at: nil, last_repository_updated_at: nil).limit(10)) + end + + projects.uniq.first(10) + end + end + def to_json(*) total = 0 |