mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 09:10:25 +08:00
FIX: Turn off auto bumping for topics with scheduled bumps
If a topic has a timer scheduled to bump a topic it should be excluded from being auto bumped.
This commit is contained in:
parent
7886a3e58a
commit
266e486037
4 changed files with 42 additions and 0 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue