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
|
end
|
||||||
|
|
||||||
def auto_bump_limiter
|
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
|
end
|
||||||
|
|
||||||
def clear_auto_bump_cache!
|
def clear_auto_bump_cache!
|
||||||
auto_bump_limiter.clear!
|
auto_bump_limiter&.clear!
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.auto_bump_topic!
|
def self.auto_bump_topic!
|
||||||
bumped = false
|
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)
|
if (auto_bumps.length > 0)
|
||||||
auto_bumps.shuffle.each do |category_id|
|
auto_bumps.shuffle.each do |category_id|
|
||||||
|
@ -406,7 +410,7 @@ class Category < ActiveRecord::Base
|
||||||
limiter = auto_bump_limiter
|
limiter = auto_bump_limiter
|
||||||
return false if !limiter.can_perform?
|
return false if !limiter.can_perform?
|
||||||
|
|
||||||
id = Topic
|
topic = Topic
|
||||||
.visible
|
.visible
|
||||||
.listable_topics
|
.listable_topics
|
||||||
.where(category_id: self.id)
|
.where(category_id: self.id)
|
||||||
|
@ -415,10 +419,10 @@ class Category < ActiveRecord::Base
|
||||||
.where('pinned_at IS NULL AND NOT closed AND NOT archived')
|
.where('pinned_at IS NULL AND NOT closed AND NOT archived')
|
||||||
.order('bumped_at ASC')
|
.order('bumped_at ASC')
|
||||||
.limit(1)
|
.limit(1)
|
||||||
.pluck(:id).first
|
.first
|
||||||
|
|
||||||
if id
|
if topic
|
||||||
Topic.where(id: id).update_all(bumped_at: Time.zone.now)
|
topic.add_small_action(Discourse.system_user, "autobumped", nil, bump: true)
|
||||||
limiter.performed!
|
limiter.performed!
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
|
|
|
@ -698,10 +698,16 @@ class Topic < ActiveRecord::Base
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_small_action(user, action_code, who = nil)
|
def add_small_action(user, action_code, who = nil, opts = {})
|
||||||
custom_fields = {}
|
custom_fields = {}
|
||||||
custom_fields["action_code_who"] = who if who.present?
|
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
|
end
|
||||||
|
|
||||||
def add_moderator_post(user, text, opts = nil)
|
def add_moderator_post(user, text, opts = nil)
|
||||||
|
|
|
@ -152,6 +152,7 @@ en:
|
||||||
user_left: "%{who} removed themselves from this message %{when}"
|
user_left: "%{who} removed themselves from this message %{when}"
|
||||||
removed_user: "removed %{who} %{when}"
|
removed_user: "removed %{who} %{when}"
|
||||||
removed_group: "removed %{who} %{when}"
|
removed_group: "removed %{who} %{when}"
|
||||||
|
autobumped: "automatically bumped topic"
|
||||||
autoclosed:
|
autoclosed:
|
||||||
enabled: 'closed %{when}'
|
enabled: 'closed %{when}'
|
||||||
disabled: 'opened %{when}'
|
disabled: 'opened %{when}'
|
||||||
|
|
|
@ -695,8 +695,11 @@ describe Category do
|
||||||
category = Fabricate(:category)
|
category = Fabricate(:category)
|
||||||
category.clear_auto_bump_cache!
|
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)
|
_post2 = create_post(category: category)
|
||||||
|
freeze_time 1.second.from_now
|
||||||
_post3 = create_post(category: category)
|
_post3 = create_post(category: category)
|
||||||
|
|
||||||
# no limits on post creation or category creation please
|
# 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(category.auto_bump_topic!).to eq(true)
|
||||||
expect(Topic.where(bumped_at: time).count).to eq(1)
|
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(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(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
|
time = 1.month.from_now
|
||||||
freeze_time time
|
freeze_time time
|
||||||
|
|
Loading…
Reference in New Issue