Preloading and missing validation
This commit is contained in:
parent
81647dc590
commit
920d08c580
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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|
|
||||
|
|
20
plugin.rb
20
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(
|
||||
|
|
Loading…
Reference in New Issue