From 235d0693000b6f1e67b7254971473c4da96d1475 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Mon, 18 Oct 2021 09:58:13 +0800 Subject: [PATCH] DEV: Reduce an additional DB query in `TopicView` for ignored users. (#14619) `TopicView#first_post_id` does a pluck which we can avoid because the first post will always have a `Post#post_number` of 1. --- lib/topic_view.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/topic_view.rb b/lib/topic_view.rb index ffb5ec08294..9110764d2a4 100644 --- a/lib/topic_view.rb +++ b/lib/topic_view.rb @@ -789,7 +789,7 @@ class TopicView ignored_user_ids = DB.query_single(sql, current_user_id: @user.id) if ignored_user_ids.present? - @filtered_posts = @filtered_posts.where.not("user_id IN (?) AND posts.id <> ?", ignored_user_ids, first_post_id) + @filtered_posts = @filtered_posts.where.not("user_id IN (?) AND posts.post_number != 1", ignored_user_ids) @contains_gaps = true end end