diff --git a/app/models/discourse_solved/solved_topic.rb b/app/models/discourse_solved/solved_topic.rb index 6f9f664..1c666e5 100644 --- a/app/models/discourse_solved/solved_topic.rb +++ b/app/models/discourse_solved/solved_topic.rb @@ -11,6 +11,7 @@ module DiscourseSolved validates :topic_id, presence: true validates :answer_post_id, presence: true + validates :accepter_user_id, presence: true end end diff --git a/db/migrate/20250318024953_copy_solved_topic_custom_field_to_discourse_solved_solved_topics.rb b/db/migrate/20250318024953_copy_solved_topic_custom_field_to_discourse_solved_solved_topics.rb index f6a9543..6633fda 100644 --- a/db/migrate/20250318024953_copy_solved_topic_custom_field_to_discourse_solved_solved_topics.rb +++ b/db/migrate/20250318024953_copy_solved_topic_custom_field_to_discourse_solved_solved_topics.rb @@ -30,7 +30,7 @@ class CopySolvedTopicCustomFieldToDiscourseSolvedSolvedTopics < ActiveRecord::Mi AND tc2.name = 'solved_auto_close_topic_timer_id' LEFT JOIN user_actions ua ON ua.target_topic_id = tc.topic_id - AND ua.action_type = #{UserAction::SOLVED} + AND ua.action_type = 15 WHERE tc.name = 'accepted_answer_post_id' AND tc.id > :last_id ORDER BY tc.topic_id, ua.created_at DESC diff --git a/db/migrate/20250318025147_add_index_for_discourse_solved_topics.rb b/db/migrate/20250318025147_add_index_for_discourse_solved_topics.rb index 42a847f..cc87d32 100644 --- a/db/migrate/20250318025147_add_index_for_discourse_solved_topics.rb +++ b/db/migrate/20250318025147_add_index_for_discourse_solved_topics.rb @@ -7,10 +7,12 @@ class AddIndexForDiscourseSolvedTopics < ActiveRecord::Migration[7.2] remove_index :discourse_solved_solved_topics, :topic_id, algorithm: :concurrently, + unique: true, if_exists: true remove_index :discourse_solved_solved_topics, :answer_post_id, algorithm: :concurrently, + unique: true, if_exists: true add_index :discourse_solved_solved_topics, :topic_id, unique: true, algorithm: :concurrently diff --git a/lib/discourse_assign/entry_point.rb b/lib/discourse_assign/entry_point.rb index 8978e6c..12821f6 100644 --- a/lib/discourse_assign/entry_point.rb +++ b/lib/discourse_assign/entry_point.rb @@ -8,9 +8,7 @@ module DiscourseAssign def self.inject(plugin) plugin.register_modifier(:assigns_reminder_assigned_topics_query) do |query| next query if !SiteSetting.ignore_solved_topics_in_assigned_reminder - # TODO: this line was modified for the custom fields migration, - # but returning this huge array is not good at all. - query.where.not(id: DiscourseSolved::SolvedTopic.pluck(:topic_id)) + query.where.not(id: DiscourseSolved::SolvedTopic.select(:topic_id)) end plugin.register_modifier(:assigned_count_for_user_query) do |query, user| diff --git a/plugin.rb b/plugin.rb index 0bac228..6bcec94 100644 --- a/plugin.rb +++ b/plugin.rb @@ -19,11 +19,6 @@ register_asset "stylesheets/mobile/solutions.scss", :mobile module ::DiscourseSolved PLUGIN_NAME = "discourse-solved" ENABLE_ACCEPTED_ANSWERS_CUSTOM_FIELD = "enable_accepted_answers" - - # throw these - AUTO_CLOSE_TOPIC_TIMER_CUSTOM_FIELD = "solved_auto_close_topic_timer_id" - ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD = "accepted_answer_post_id" - IS_ACCEPTED_ANSWER_CUSTOM_FIELD = "is_accepted_answer" end require_relative "lib/discourse_solved/engine.rb" @@ -170,13 +165,18 @@ after_initialize do end # TODO: Preload fields in - # - TopicList - answer_post_id - # - Search - answer_post_id # - CategoryList - answer_post_id ?? for what - # topic_view_post_custom_fields_allowlister { [::DiscourseSolved::IS_ACCEPTED_ANSWER_CUSTOM_FIELD] } - # TopicList.preloaded_custom_fields << ::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD - # Search.preloaded_topic_custom_fields << ::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD # CategoryList.preloaded_topic_custom_fields << ::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD + + # - TopicList - answer_post_id + register_category_list_topics_preloader_associations(:solved) if SiteSetting.solved_enabled + register_topic_preloader_associations(:solved) if SiteSetting.solved_enabled + + # - Search - answer_post_id + Search.on_preload do |results| + next unless SiteSetting.solved_enabled + results.posts = results.posts.includes(topic: :solved) + end Site.preloaded_category_custom_fields << ::DiscourseSolved::ENABLE_ACCEPTED_ANSWERS_CUSTOM_FIELD add_api_key_scope(