PERF: N+1 queries while loading `Post#event` in a topic.

PERF: N+1 queries while loading Post#event in a topic.

diff --git a/plugin.rb b/plugin.rb
index 8df356b..6a80b8b 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -196,6 +196,13 @@ after_initialize do
     )
   end
 
+  # TODO: Switch to an official plugin API once support for it has landed.
+  TopicView.on_preload do |topic_view|
+    if SiteSetting.discourse_post_event_enabled
+      topic_view.instance_variable_set(:@posts, topic_view.posts.includes(:event))
+    end
+  end
+
   add_to_serializer(:post, :event) do
     DiscoursePostEvent::EventSerializer.new(
       object.event,

GitHub sha: d469260b

This commit appears in #140 which was approved by techAPJ. It was merged by tgxworld.