PERF: Remove N+1 queries on search topic list item serializer.

PERF: Remove N+1 queries on search topic list item serializer.

diff --git a/plugin.rb b/plugin.rb
index 1f58739..4f76f18 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -505,6 +505,7 @@ SQL
 
   TopicList.preloaded_custom_fields << "accepted_answer_post_id" if TopicList.respond_to? :preloaded_custom_fields
   Site.preloaded_category_custom_fields << "enable_accepted_answers" if Site.respond_to? :preloaded_category_custom_fields
+  Search.preloaded_topic_custom_fields << "accepted_answer_post_id" if Search.respond_to? :preloaded_topic_custom_fields
 
   if CategoryList.respond_to?(:preloaded_topic_custom_fields)
     CategoryList.preloaded_topic_custom_fields << "accepted_answer_post_id"

GitHub sha: ca2d5376

Do we need to preload this if the solved plugin isn’t enabled?

Yes we shouldn’t preload if plugin is disabled.

I like to do this in plugin instance itself. I hope we have valid reasons (maybe multisite) to not doing it.

We do we need to preload the custom fields when it is not going to be used? Since preloaded_topic_custom_fields is a set, I would just add the field to the set only when we need to.

It’s a typo :stuck_out_tongue_winking_eye:

If we checked the enable setting while adding the preloaded custom field then the custom fields won’t included if the plugin is enabled after the initial load. In that case we may have to rethink the whole strategy here.