Revert "FEATURE: Use the top period default for users who have been inactive or are new"

This commit is contained in:
Régis Hanol
2016-10-11 17:56:46 +02:00
committed by GitHub
parent e7749da007
commit ddcc084d22
4 changed files with 12 additions and 64 deletions

View File

@@ -171,7 +171,7 @@ class ListController < ApplicationController
def top(options=nil)
options ||= {}
period = ListController.best_period_for(current_user.try(:previous_visit_at), options[:category], SiteSetting.top_page_default_timeframe.to_sym)
period = ListController.best_period_for(current_user.try(:previous_visit_at), options[:category])
send("top_#{period}", options)
end
@@ -327,14 +327,14 @@ class ListController < ApplicationController
exclude_category_ids.pluck(:id)
end
def self.best_period_for(previous_visit_at, category_id=nil, default_period=nil)
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")
top_topics = top_topics.joins(:topic).where("topics.category_id = ?", category_id) if category_id
return period if top_topics.count >= SiteSetting.topics_per_period_in_top_page
end
default_period
# default period is yearly
SiteSetting.top_page_default_timeframe.to_sym
end
def self.best_periods_for(date)

View File

@@ -97,8 +97,13 @@ class SiteSetting < ActiveRecord::Base
].flatten.to_set
end
def self.min_redirected_to_top_period(duration=nil)
return ListController.best_period_for(duration)
def self.min_redirected_to_top_period
TopTopic.sorted_periods.each do |p|
period = p[0]
return period if TopTopic.topics_per_period(period) >= SiteSetting.topics_per_period_in_top_page
end
# not enough topics
nil
end
def self.email_polling_enabled?

View File

@@ -90,7 +90,7 @@ class UserOption < ActiveRecord::Base
# top must be in the top_menu
return unless SiteSetting.top_menu =~ /(^|\|)top(\||$)/i
# not enough topics
return unless period = SiteSetting.min_redirected_to_top_period(1.days.ago)
return unless period = SiteSetting.min_redirected_to_top_period
if !user.seen_before? || (user.trust_level == 0 && !redirected_to_top_yet?)
update_last_redirected_to_top!