A platform for community discussion. Free, open, simple.
PERF: Preload topic thumbnails for all topic lists (#11238)
David Taylor86ffa3ba4f6c
diff --git a/app/models/topic_list.rb b/app/models/topic_list.rbindex f191af9e5a0..41bc79f46e4 100644--- a/app/models/topic_list.rb+++ b/app/models/topic_list.rb@@ -130,6 +130,8 @@ class TopicList < DraftableListft.topic_list = selfend+ ActiveRecord::Associations::Preloader.new.preload(@topics, [:image_upload, topic_thumbnails: :optimized_image])+if preloaded_custom_fields.present?Topic.preload_custom_fields(@topics, preloaded_custom_fields)enddiff --git a/lib/topic_query.rb b/lib/topic_query.rbindex a5f4bd7cd6f..2d4041843b3 100644--- a/lib/topic_query.rb+++ b/lib/topic_query.rb@@ -873,8 +873,6 @@ class TopicQueryresult = result.where('topics.posts_count <= ?', options[:max_posts]) if options[:max_posts].present?result = result.where('topics.posts_count >= ?', options[:min_posts]) if options[:min_posts].present?- result = preload_thumbnails(result)-result = TopicQuery.apply_custom_filters(result, self)result@@ -1115,10 +1113,6 @@ class TopicQueryresult.order('topics.bumped_at DESC')end- def preload_thumbnails(result)- result.preload(:image_upload, topic_thumbnails: :optimized_image)- end-privatedef append_read_state(list, group)