@@ -118,23 +118,23 @@ def self.unaccept_answer!(post, topic: nil)
118
118
119
119
DistributedMutex . synchronize ( "discourse_solved_toggle_answer_#{ topic . id } " ) do
120
120
solved = topic . solved
121
- solved . topic_timer . destroy! if solved . topic_timer
122
121
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
131
133
132
134
if WebHook . active_web_hooks ( :unaccepted_solution ) . exists?
133
135
payload = WebHook . generate_payload ( :post , post )
134
136
WebHook . enqueue_solved_hooks ( :unaccepted_solution , post , payload )
135
137
end
136
-
137
- solved . destroy!
138
138
DiscourseEvent . trigger ( :unaccepted_solution , post )
139
139
end
140
140
end
@@ -164,15 +164,8 @@ def self.skip_db?
164
164
] . each { |klass | klass . include ( DiscourseSolved ::TopicAnswerMixin ) }
165
165
end
166
166
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
172
167
register_category_list_topics_preloader_associations ( :solved ) if SiteSetting . solved_enabled
173
168
register_topic_preloader_associations ( :solved ) if SiteSetting . solved_enabled
174
-
175
- # - Search - answer_post_id
176
169
Search . on_preload do |results |
177
170
next unless SiteSetting . solved_enabled
178
171
results . posts = results . posts . includes ( topic : :solved )
0 commit comments