Skip to content

A platform for community discussion. Free, open, simple.

FIX: Turn off auto bumping for topics with scheduled bumps

Blake Erickson266e4860378d
diff --git a/app/models/category.rb b/app/models/category.rb
index cb50cef6519..25aeff75fcc 100644
--- a/app/models/category.rb
+++ b/app/models/category.rb
@@ -532,6 +532,7 @@ class Category < ActiveRecord::Base
topic = relation
.visible
.listable_topics
+ .exclude_scheduled_bump_topics
.where(category_id: self.id)
.where('id <> ?', self.topic_id)
.where('bumped_at < ?', 1.day.ago)
diff --git a/app/models/topic.rb b/app/models/topic.rb
index 8531738b6a2..b5378915979 100644
--- a/app/models/topic.rb
+++ b/app/models/topic.rb
@@ -158,6 +158,8 @@ class Topic < ActiveRecord::Base
scope :created_since, lambda { |time_ago| where('topics.created_at > ?', time_ago) }
+ scope :exclude_scheduled_bump_topics, -> { where.not(id: TopicTimer.scheduled_bump_topics) }
+
scope :secured, lambda { |guardian = nil|
ids = guardian.secure_category_ids if guardian
diff --git a/app/models/topic_timer.rb b/app/models/topic_timer.rb
index c6213a164e7..8c7f3056e67 100644
--- a/app/models/topic_timer.rb
+++ b/app/models/topic_timer.rb
@@ -17,6 +17,8 @@ class TopicTimer < ActiveRecord::Base
validate :ensure_update_will_happen
+ scope :scheduled_bump_topics, -> { where(status_type: 6, deleted_at: nil).pluck(:topic_id) }
+
before_save do
self.created_at ||= Time.zone.now if execute_at
self.public_type = self.public_type?
diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rb
index 37b37037fba..f268c2c7356 100644
--- a/spec/models/category_spec.rb
+++ b/spec/models/category_spec.rb
@@ -891,6 +891,43 @@ describe Category do
expect(Category.auto_bump_topic!).to eq(false)
end
+
+ it 'should not automatically bump topics with a bump scheduled' do
+ freeze_time 1.second.ago
+ category = Fabricate(:category_with_definition)
+ category.clear_auto_bump_cache!
+
+ freeze_time 1.second.from_now
+ post1 = create_post(category: category)
+
+ # no limits on post creation or category creation please
+ RateLimiter.enable
+
+ time = 1.month.from_now
+ freeze_time time
+
+ expect(category.auto_bump_topic!).to eq(false)
+ expect(Topic.where(bumped_at: time).count).to eq(0)
+
+ category.num_auto_bump_daily = 2
+ category.save!
+
+ topic = Topic.find_by_id(post1.topic_id)
+
+ TopicTimer.create!(
+ user_id: -1,
+ topic: topic,
+ execute_at: 1.hour.from_now,
+ status_type: TopicTimer.types[:bump]
+ )
+
+ expect(Topic.joins(:topic_timers).where(topic_timers: { status_type: 6, deleted_at: nil }).count).to eq(1)
+
+ expect(category.auto_bump_topic!).to eq(false)
+ expect(Topic.where(bumped_at: time).count).to eq(0)
+ # does not include a bump message
+ expect(post1.topic.reload.posts_count).to eq(1)
+ end
end
describe "validate permissions compatibility" do