From cb8f3f1a6fcc01666d1f32e1d3e40777bf249181 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 18 Apr 2013 09:34:58 +1000 Subject: [PATCH] fix feature job so it does not fail out when a topic is deleted --- lib/jobs/feature_topic_users.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/jobs/feature_topic_users.rb b/lib/jobs/feature_topic_users.rb index a13e5f79b32..58aa4380bb2 100644 --- a/lib/jobs/feature_topic_users.rb +++ b/lib/jobs/feature_topic_users.rb @@ -3,8 +3,21 @@ module Jobs class FeatureTopicUsers < Jobs::Base def execute(args) - topic = Topic.where(id: args[:topic_id]).first - raise Discourse::InvalidParameters.new(:topic_id) unless topic.present? + topic_id = args[:topic_id] + raise Discourse::InvalidParameters.new(:topic_id) unless topic_id.present? + + topic = Topic.where(id: topic_id).first + + # there are 3 cases here + # 1. topic was atomically nuked, this should be skipped + # 2. topic was deleted, this should be skipped + # 3. error an incorrect topic_id was sent + + unless topic.present? + max_id = Topic.with_deleted.maximum(:id).to_i + raise Discourse::InvalidParameters.new(:topic_id) if max_id < topic_id + return + end topic.feature_topic_users(args) end