From 040584fc688009caa4bdd6defcf4f0d6d9bd23cb Mon Sep 17 00:00:00 2001 From: Tanmay Deep Sharma Date: Tue, 7 Oct 2025 10:58:57 +0200 Subject: [PATCH] optimise the label query by using cached_label_list instead of joins --- app/finders/conversation_finder.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/finders/conversation_finder.rb b/app/finders/conversation_finder.rb index d43ed31e7..a9f10b115 100644 --- a/app/finders/conversation_finder.rb +++ b/app/finders/conversation_finder.rb @@ -156,7 +156,8 @@ class ConversationFinder def filter_by_labels return unless params[:labels] - @conversations = @conversations.tagged_with(params[:labels], any: true) + pattern = params[:labels].map { |label| Regexp.escape(label) }.join('|') + @conversations = @conversations.where('cached_label_list ~ ?', "\\y(#{pattern})\\y") end def filter_by_source_id