A platform for community discussion. Free, open, simple.
correct auto bump topic logic
Sam91266cdabb88
diff --git a/app/jobs/scheduled/periodical_updates.rb b/app/jobs/scheduled/periodical_updates.rbindex 5025f999711..73f480494ab 100644--- a/app/jobs/scheduled/periodical_updates.rb+++ b/app/jobs/scheduled/periodical_updates.rb@@ -49,13 +49,7 @@ module JobsSiteSetting.min_new_topics_time = last_new_topic.created_at.to_iend- 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!nilenddiff --git a/app/models/category.rb b/app/models/category.rbindex e3fc9bc7ded..f8ebb396dca 100644--- a/app/models/category.rb+++ b/app/models/category.rb@@ -385,6 +385,19 @@ class Category < ActiveRecord::Baseauto_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 thresholddef auto_bump_topic!diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rbindex 54828be487a..18880170cfb 100644--- a/spec/models/category_spec.rb+++ b/spec/models/category_spec.rb@@ -686,10 +686,6 @@ describe Category doenddescribe 'auto bump' do- before do- RateLimiter.enable- end-after doRateLimiter.disableend@@ -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_nowfreeze_time time@@ -721,6 +720,12 @@ describe Category doexpect(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)endend