FEATURE: no need to cap new and unread together anymore

- leave unread alone
- cap new at 500 per site, with a site setting
This commit is contained in:
Sam 2015-10-01 17:17:15 +10:00
parent 9bb7a3884b
commit 6f43b575a8
5 changed files with 2 additions and 38 deletions

View File

@ -300,9 +300,6 @@ class ApplicationController < ActionController::Base
def preload_current_user_data
store_preloaded("currentUser", MultiJson.dump(CurrentUserSerializer.new(current_user, scope: guardian, root: false)))
report = TopicTrackingState.report(current_user.id)
if report.length >= SiteSetting.max_tracked_new_unread.to_i
TopicUser.cap_unread_later(current_user.id)
end
serializer = ActiveModel::ArraySerializer.new(report, each_serializer: TopicTrackingStateSerializer)
store_preloaded("topicTrackingStates", MultiJson.dump(serializer))
end

View File

@ -33,9 +33,7 @@ module Jobs
Discourse.handle_job_exception(hash[:ex], error_context(args, "Rebaking user id #{user_id}", user_id: user_id))
end
TopicUser.cap_unread_backlog!
offset = (SiteSetting.max_tracked_new_unread * (2/5.0)).to_i
offset = (SiteSetting.max_new_topics).to_i
last_new_topic = Topic.order('created_at desc').offset(offset).select(:created_at).first
if last_new_topic
SiteSetting.min_new_topics_time = last_new_topic.created_at.to_i

View File

@ -306,21 +306,6 @@ SQL
TopicUser.exec_sql(sql, user_id: user_id, count: count)
end
def self.unread_cap_key
"unread_cap_user".freeze
end
def self.cap_unread_later(user_id)
$redis.hset TopicUser.unread_cap_key, user_id, ""
end
def self.cap_unread_backlog!
$redis.hkeys(unread_cap_key).map(&:to_i).each do |user_id|
cap_unread!(user_id, (SiteSetting.max_tracked_new_unread * (2/5.0)).to_i)
$redis.hdel unread_cap_key, user_id
end
end
def self.ensure_consistency!(topic_id=nil)
update_post_action_cache(topic_id: topic_id)

View File

@ -764,7 +764,7 @@ developer:
migrate_to_new_scheme:
hidden: true
default: false
max_tracked_new_unread:
max_new_topics:
default: 500
client: true
hidden: true

View File

@ -41,8 +41,6 @@ describe TopicTrackingState do
it "correctly handles capping" do
$redis.del TopicUser.unread_cap_key
user = Fabricate(:user)
post1 = create_post
@ -67,20 +65,6 @@ describe TopicTrackingState do
report = TopicTrackingState.report(user.id)
expect(report.length).to eq(3)
SiteSetting.max_tracked_new_unread = 5
# business logic, we allow for 2/5th new .. 2/5th unread ... 1/5th buffer
TopicUser.cap_unread_backlog!
report = TopicTrackingState.report(user.id)
expect(report.length).to eq(3)
TopicUser.cap_unread_later(user.id)
TopicUser.cap_unread_backlog!
report = TopicTrackingState.report(user.id)
expect(report.length).to eq(2)
end
it "correctly gets the tracking state" do