diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/explore/projects_controller.rb | 2 | ||||
-rw-r--r-- | app/finders/trending_projects_finder.rb | 13 |
2 files changed, 10 insertions, 5 deletions
diff --git a/app/controllers/explore/projects_controller.rb b/app/controllers/explore/projects_controller.rb index 88a0c18180b..38e5943eb76 100644 --- a/app/controllers/explore/projects_controller.rb +++ b/app/controllers/explore/projects_controller.rb @@ -21,7 +21,7 @@ class Explore::ProjectsController < Explore::ApplicationController end def trending - @projects = TrendingProjectsFinder.new.execute(current_user) + @projects = TrendingProjectsFinder.new.execute @projects = filter_projects(@projects) @projects = @projects.page(params[:page]) diff --git a/app/finders/trending_projects_finder.rb b/app/finders/trending_projects_finder.rb index 81a12403801..c1e434d9926 100644 --- a/app/finders/trending_projects_finder.rb +++ b/app/finders/trending_projects_finder.rb @@ -1,11 +1,16 @@ +# Finder for retrieving public trending projects in a given time range. class TrendingProjectsFinder - def execute(current_user, start_date = 1.month.ago) - projects_for(current_user).trending(start_date) + # current_user - The currently logged in User, if any. + # last_months - The number of months to limit the trending data to. + def execute(months_limit = 1) + Rails.cache.fetch(cache_key_for(months_limit), expires_in: 1.day) do + Project.public_only.trending(months_limit.months.ago) + end end private - def projects_for(current_user) - ProjectsFinder.new.execute(current_user) + def cache_key_for(months) + "trending_projects/#{months}" end end |