Skip to content

Commit ba32049

Browse files
committed
transaction
1 parent 920d08c commit ba32049

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

plugin.rb

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,23 +118,23 @@ def self.unaccept_answer!(post, topic: nil)
118118

119119
DistributedMutex.synchronize("discourse_solved_toggle_answer_#{topic.id}") do
120120
solved = topic.solved
121-
solved.topic_timer.destroy! if solved.topic_timer
122121

123-
UserAction.where(action_type: UserAction::SOLVED, target_post_id: post.id).destroy_all
124-
125-
Notification.find_by(
126-
notification_type: Notification.types[:custom],
127-
user_id: post.user_id,
128-
topic_id: post.topic_id,
129-
post_number: post.post_number,
130-
)&.destroy!
122+
ActiveRecord::Base.transaction do
123+
UserAction.where(action_type: UserAction::SOLVED, target_post_id: post.id).destroy_all
124+
Notification.find_by(
125+
notification_type: Notification.types[:custom],
126+
user_id: post.user_id,
127+
topic_id: post.topic_id,
128+
post_number: post.post_number,
129+
)&.destroy!
130+
solved.topic_timer.destroy! if solved.topic_timer
131+
solved.destroy!
132+
end
131133

132134
if WebHook.active_web_hooks(:unaccepted_solution).exists?
133135
payload = WebHook.generate_payload(:post, post)
134136
WebHook.enqueue_solved_hooks(:unaccepted_solution, post, payload)
135137
end
136-
137-
solved.destroy!
138138
DiscourseEvent.trigger(:unaccepted_solution, post)
139139
end
140140
end
@@ -164,15 +164,8 @@ def self.skip_db?
164164
].each { |klass| klass.include(DiscourseSolved::TopicAnswerMixin) }
165165
end
166166

167-
# TODO: Preload fields in
168-
# - CategoryList - answer_post_id ?? for what
169-
# CategoryList.preloaded_topic_custom_fields << ::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD
170-
171-
# - TopicList - answer_post_id
172167
register_category_list_topics_preloader_associations(:solved) if SiteSetting.solved_enabled
173168
register_topic_preloader_associations(:solved) if SiteSetting.solved_enabled
174-
175-
# - Search - answer_post_id
176169
Search.on_preload do |results|
177170
next unless SiteSetting.solved_enabled
178171
results.posts = results.posts.includes(topic: :solved)

0 commit comments

Comments
 (0)