mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 17:12:45 +08:00
correct auto bump topic logic
This commit is contained in:
parent
e7102c73fb
commit
91266cdabb
|
@ -49,13 +49,7 @@ module Jobs
|
|||
SiteSetting.min_new_topics_time = last_new_topic.created_at.to_i
|
||||
end
|
||||
|
||||
auto_bumps = CategoryCustomField.where(name: Category::NUM_AUTO_BUMP_DAILY).pluck(:id)
|
||||
|
||||
if (auto_bumps.length > 0)
|
||||
auto_bumps.shuffle.each do |category_id|
|
||||
break if Category.find_by(id: category_id)&.auto_bump_topic!
|
||||
end
|
||||
end
|
||||
Category.auto_bump_topic!
|
||||
|
||||
nil
|
||||
end
|
||||
|
|
|
@ -385,6 +385,19 @@ class Category < ActiveRecord::Base
|
|||
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)
|
||||
|
||||
if (auto_bumps.length > 0)
|
||||
auto_bumps.shuffle.each do |category_id|
|
||||
bumped = Category.find_by(id: category_id)&.auto_bump_topic!
|
||||
break if bumped
|
||||
end
|
||||
end
|
||||
bumped
|
||||
end
|
||||
|
||||
# will automatically bump a single topic
|
||||
# if number of automatically bumped topics is smaller than threshold
|
||||
def auto_bump_topic!
|
||||
|
|
|
@ -686,10 +686,6 @@ describe Category do
|
|||
end
|
||||
|
||||
describe 'auto bump' do
|
||||
before do
|
||||
RateLimiter.enable
|
||||
end
|
||||
|
||||
after do
|
||||
RateLimiter.disable
|
||||
end
|
||||
|
@ -703,6 +699,9 @@ describe Category do
|
|||
_post2 = create_post(category: category)
|
||||
_post3 = create_post(category: category)
|
||||
|
||||
# no limits on post creation or category creation please
|
||||
RateLimiter.enable
|
||||
|
||||
time = 1.month.from_now
|
||||
freeze_time time
|
||||
|
||||
|
@ -721,6 +720,12 @@ describe Category do
|
|||
expect(category.auto_bump_topic!).to eq(false)
|
||||
expect(Topic.where(bumped_at: time).count).to eq(2)
|
||||
|
||||
time = 1.month.from_now
|
||||
freeze_time time
|
||||
|
||||
category.auto_bump_limiter.clear!
|
||||
expect(Category.auto_bump_topic!).to eq(true)
|
||||
expect(Topic.where(bumped_at: time).count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user