mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
BUGFIX: correctly auto-select /top time range when filtering on a category
This commit is contained in:
parent
b232736242
commit
3fde28e108
1 changed files with 8 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue