Skip to content

Commit 920d08c

Browse files
committed
Preloading and missing validation
1 parent 81647dc commit 920d08c

File tree

5 files changed

+15
-14
lines changed

5 files changed

+15
-14
lines changed

app/models/discourse_solved/solved_topic.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class SolvedTopic < ActiveRecord::Base
1111

1212
validates :topic_id, presence: true
1313
validates :answer_post_id, presence: true
14+
validates :accepter_user_id, presence: true
1415
end
1516
end
1617

db/migrate/20250318024953_copy_solved_topic_custom_field_to_discourse_solved_solved_topics.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def up
3030
AND tc2.name = 'solved_auto_close_topic_timer_id'
3131
LEFT JOIN user_actions ua
3232
ON ua.target_topic_id = tc.topic_id
33-
AND ua.action_type = #{UserAction::SOLVED}
33+
AND ua.action_type = 15
3434
WHERE tc.name = 'accepted_answer_post_id'
3535
AND tc.id > :last_id
3636
ORDER BY tc.topic_id, ua.created_at DESC

db/migrate/20250318025147_add_index_for_discourse_solved_topics.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ def change
77
remove_index :discourse_solved_solved_topics,
88
:topic_id,
99
algorithm: :concurrently,
10+
unique: true,
1011
if_exists: true
1112
remove_index :discourse_solved_solved_topics,
1213
:answer_post_id,
1314
algorithm: :concurrently,
15+
unique: true,
1416
if_exists: true
1517

1618
add_index :discourse_solved_solved_topics, :topic_id, unique: true, algorithm: :concurrently

lib/discourse_assign/entry_point.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ class EntryPoint
88
def self.inject(plugin)
99
plugin.register_modifier(:assigns_reminder_assigned_topics_query) do |query|
1010
next query if !SiteSetting.ignore_solved_topics_in_assigned_reminder
11-
# TODO: this line was modified for the custom fields migration,
12-
# but returning this huge array is not good at all.
13-
query.where.not(id: DiscourseSolved::SolvedTopic.pluck(:topic_id))
11+
query.where.not(id: DiscourseSolved::SolvedTopic.select(:topic_id))
1412
end
1513

1614
plugin.register_modifier(:assigned_count_for_user_query) do |query, user|

plugin.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919
module ::DiscourseSolved
2020
PLUGIN_NAME = "discourse-solved"
2121
ENABLE_ACCEPTED_ANSWERS_CUSTOM_FIELD = "enable_accepted_answers"
22-
23-
# throw these
24-
AUTO_CLOSE_TOPIC_TIMER_CUSTOM_FIELD = "solved_auto_close_topic_timer_id"
25-
ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD = "accepted_answer_post_id"
26-
IS_ACCEPTED_ANSWER_CUSTOM_FIELD = "is_accepted_answer"
2722
end
2823

2924
require_relative "lib/discourse_solved/engine.rb"
@@ -170,13 +165,18 @@ def self.skip_db?
170165
end
171166

172167
# TODO: Preload fields in
173-
# - TopicList - answer_post_id
174-
# - Search - answer_post_id
175168
# - CategoryList - answer_post_id ?? for what
176-
# topic_view_post_custom_fields_allowlister { [::DiscourseSolved::IS_ACCEPTED_ANSWER_CUSTOM_FIELD] }
177-
# TopicList.preloaded_custom_fields << ::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD
178-
# Search.preloaded_topic_custom_fields << ::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD
179169
# CategoryList.preloaded_topic_custom_fields << ::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD
170+
171+
# - TopicList - answer_post_id
172+
register_category_list_topics_preloader_associations(:solved) if SiteSetting.solved_enabled
173+
register_topic_preloader_associations(:solved) if SiteSetting.solved_enabled
174+
175+
# - Search - answer_post_id
176+
Search.on_preload do |results|
177+
next unless SiteSetting.solved_enabled
178+
results.posts = results.posts.includes(topic: :solved)
179+
end
180180
Site.preloaded_category_custom_fields << ::DiscourseSolved::ENABLE_ACCEPTED_ANSWERS_CUSTOM_FIELD
181181

182182
add_api_key_scope(

0 commit comments

Comments
 (0)