mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 10:20:58 -06:00
FEATURE: adjust autobump system
- We spread out bumping through the day, if you are bumping 4 topics then a topic will be bumped every 6 hours - We add a small, bumping action at the bottom of the post to denote a topic got bumped
This commit is contained in:
parent
f146f94ef6
commit
02628883d2
@ -378,16 +378,20 @@ class Category < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def auto_bump_limiter
|
||||
RateLimiter.new(nil, "auto_bump_limit_#{self.id}", num_auto_bump_daily.to_i, 86400)
|
||||
return nil if num_auto_bump_daily.to_i == 0
|
||||
RateLimiter.new(nil, "auto_bump_limit_#{self.id}", 1, 86400 / num_auto_bump_daily.to_i)
|
||||
end
|
||||
|
||||
def clear_auto_bump_cache!
|
||||
auto_bump_limiter.clear!
|
||||
auto_bump_limiter&.clear!
|
||||
end
|
||||
|
||||
def self.auto_bump_topic!
|
||||
bumped = false
|
||||
auto_bumps = CategoryCustomField.where(name: Category::NUM_AUTO_BUMP_DAILY).pluck(:category_id)
|
||||
auto_bumps = CategoryCustomField
|
||||
.where(name: Category::NUM_AUTO_BUMP_DAILY)
|
||||
.where('value::int > 0')
|
||||
.pluck(:category_id)
|
||||
|
||||
if (auto_bumps.length > 0)
|
||||
auto_bumps.shuffle.each do |category_id|
|
||||
@ -406,7 +410,7 @@ class Category < ActiveRecord::Base
|
||||
limiter = auto_bump_limiter
|
||||
return false if !limiter.can_perform?
|
||||
|
||||
id = Topic
|
||||
topic = Topic
|
||||
.visible
|
||||
.listable_topics
|
||||
.where(category_id: self.id)
|
||||
@ -415,10 +419,10 @@ class Category < ActiveRecord::Base
|
||||
.where('pinned_at IS NULL AND NOT closed AND NOT archived')
|
||||
.order('bumped_at ASC')
|
||||
.limit(1)
|
||||
.pluck(:id).first
|
||||
.first
|
||||
|
||||
if id
|
||||
Topic.where(id: id).update_all(bumped_at: Time.zone.now)
|
||||
if topic
|
||||
topic.add_small_action(Discourse.system_user, "autobumped", nil, bump: true)
|
||||
limiter.performed!
|
||||
true
|
||||
else
|
||||
|
@ -698,10 +698,16 @@ class Topic < ActiveRecord::Base
|
||||
true
|
||||
end
|
||||
|
||||
def add_small_action(user, action_code, who = nil)
|
||||
def add_small_action(user, action_code, who = nil, opts = {})
|
||||
custom_fields = {}
|
||||
custom_fields["action_code_who"] = who if who.present?
|
||||
add_moderator_post(user, nil, post_type: Post.types[:small_action], action_code: action_code, custom_fields: custom_fields)
|
||||
opts = opts.merge(
|
||||
post_type: Post.types[:small_action],
|
||||
action_code: action_code,
|
||||
custom_fields: custom_fields
|
||||
)
|
||||
|
||||
add_moderator_post(user, nil, opts)
|
||||
end
|
||||
|
||||
def add_moderator_post(user, text, opts = nil)
|
||||
|
@ -152,6 +152,7 @@ en:
|
||||
user_left: "%{who} removed themselves from this message %{when}"
|
||||
removed_user: "removed %{who} %{when}"
|
||||
removed_group: "removed %{who} %{when}"
|
||||
autobumped: "automatically bumped topic"
|
||||
autoclosed:
|
||||
enabled: 'closed %{when}'
|
||||
disabled: 'opened %{when}'
|
||||
|
@ -695,8 +695,11 @@ describe Category do
|
||||
category = Fabricate(:category)
|
||||
category.clear_auto_bump_cache!
|
||||
|
||||
_post1 = create_post(category: category)
|
||||
freeze_time 1.second.from_now
|
||||
post1 = create_post(category: category)
|
||||
freeze_time 1.second.from_now
|
||||
_post2 = create_post(category: category)
|
||||
freeze_time 1.second.from_now
|
||||
_post3 = create_post(category: category)
|
||||
|
||||
# no limits on post creation or category creation please
|
||||
@ -713,12 +716,17 @@ describe Category do
|
||||
|
||||
expect(category.auto_bump_topic!).to eq(true)
|
||||
expect(Topic.where(bumped_at: time).count).to eq(1)
|
||||
# our extra bump message
|
||||
expect(post1.topic.reload.posts_count).to eq(2)
|
||||
|
||||
time = time + 13.hours
|
||||
freeze_time time
|
||||
|
||||
expect(category.auto_bump_topic!).to eq(true)
|
||||
expect(Topic.where(bumped_at: time).count).to eq(2)
|
||||
expect(Topic.where(bumped_at: time).count).to eq(1)
|
||||
|
||||
expect(category.auto_bump_topic!).to eq(false)
|
||||
expect(Topic.where(bumped_at: time).count).to eq(2)
|
||||
expect(Topic.where(bumped_at: time).count).to eq(1)
|
||||
|
||||
time = 1.month.from_now
|
||||
freeze_time time
|
||||
|
Loading…
Reference in New Issue
Block a user