fix: Avoid joining tables to fix the distinct value query (#7965)

DISTINCT query with custom attributes return an error. To avoid the error, this PR refactors the query to include tags only when it is required.

Fixes #7931
Fixes #7836

Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
Pranav Raj S
2023-09-22 19:48:56 -07:00
committed by GitHub
parent dd0930d75e
commit ff915dd2ea
4 changed files with 94 additions and 30 deletions

View File

@@ -46,7 +46,7 @@ class Conversations::FilterService < FilterService
" (conversations.#{attribute_key})::#{current_filter['data_type']} #{filter_operator_value}#{current_filter['data_type']} #{query_operator} "
when 'standard'
if attribute_key == 'labels'
" tags.name #{filter_operator_value} #{query_operator} "
tag_filter_query('Conversation', 'conversations', query_hash, current_index)
else
" conversations.#{attribute_key} #{filter_operator_value} #{query_operator} "
end
@@ -54,7 +54,9 @@ class Conversations::FilterService < FilterService
end
def base_relation
@account.conversations.left_outer_joins(:labels)
@account.conversations.includes(
:taggings, :inbox, { assignee: { avatar_attachment: [:blob] } }, { contact: { avatar_attachment: [:blob] } }, :team, :messages, :contact_inbox
)
end
def current_page
@@ -62,10 +64,6 @@ class Conversations::FilterService < FilterService
end
def conversations
@conversations = @conversations.includes(
:taggings, :inbox, { assignee: { avatar_attachment: [:blob] } }, { contact: { avatar_attachment: [:blob] } }, :team, :messages, :contact_inbox
)
@conversations.latest.page(current_page)
end
end