From 3fde28e108aa2ca1a0caa8aefc0ab46e29974539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 14 May 2014 11:49:50 +0200 Subject: [PATCH] BUGFIX: correctly auto-select /top time range when filtering on a category --- app/controllers/list_controller.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb index acc54d95498..11adede2cb6 100644 --- a/app/controllers/list_controller.rb +++ b/app/controllers/list_controller.rb @@ -314,7 +314,7 @@ class ListController < ApplicationController topic_query = TopicQuery.new(current_user, options) if current_user.present? - periods = [ListController.best_period_for(current_user.previous_visit_at)] + periods = [ListController.best_period_for(current_user.previous_visit_at, options[:category])] else periods = TopTopic.periods end @@ -324,9 +324,13 @@ class ListController < ApplicationController top end - def self.best_period_for(previous_visit_at) - ListController.best_periods_for(previous_visit_at).each do |period| - return period if TopTopic.where("#{period}_score > 0").count >= SiteSetting.topics_per_period_in_top_page + def self.best_period_for(previous_visit_at, category_id=nil) + best_periods_for(previous_visit_at).each do |period| + top_topics = TopTopic.where("#{period}_score > 0") + if category_id + top_topics = top_topics.joins(:topic).where("topics.category_id = ?", category_id) + end + return period if top_topics.count >= SiteSetting.topics_per_period_in_top_page end # default period is yearly :yearly