From ca7e912c04158cc4676270db702318e1a7f6d913 Mon Sep 17 00:00:00 2001 From: Tejaswini Chile Date: Fri, 23 Dec 2022 17:16:02 +0530 Subject: [PATCH] codeclimate fix --- .../concerns/multi_searchable_helpers.rb | 24 +++++++++++++++++++ app/models/conversation.rb | 22 ----------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/app/models/concerns/multi_searchable_helpers.rb b/app/models/concerns/multi_searchable_helpers.rb index b2c33906a..fc0f4f309 100644 --- a/app/models/concerns/multi_searchable_helpers.rb +++ b/app/models/concerns/multi_searchable_helpers.rb @@ -21,6 +21,30 @@ module MultiSearchableHelpers inbox_id: inbox_id ) end + + # NOTE: To add multi search records with conversation_id associated to contacts for previously added records. + # We can not find conversation_id from contacts directly so we added this joins here. + def self.rebuild_pg_search_documents(_account_id) + return unless name == 'Conversation' + end + end + + def rebuild_pg_search_documents(account_id) + connection.execute <<~SQL.squish + INSERT INTO pg_search_documents (searchable_type, searchable_id, content, account_id, conversation_id, inbox_id, created_at, updated_at) + SELECT 'Conversation' AS searchable_type, + conversations.id AS searchable_id, + CONCAT_WS(' ', conversations.display_id, contacts.email, contacts.name, contacts.phone_number, conversations.account_id) AS content, + conversations.account_id::int AS account_id, + conversations.id::int AS conversation_id, + conversations.inbox_id::int AS inbox_id, + now() AS created_at, + now() AS updated_at + FROM conversations + INNER JOIN contacts + ON conversations.contact_id = contacts.id + WHERE conversations.account_id = #{account_id} + SQL end def contact_pg_search_record diff --git a/app/models/conversation.rb b/app/models/conversation.rb index 63055b79b..d1619420c 100644 --- a/app/models/conversation.rb +++ b/app/models/conversation.rb @@ -202,28 +202,6 @@ class Conversation < ApplicationRecord messages.chat.last(5) end - # NOTE: To add multi search records with conversation_id associated to contacts for previously added records. - # We can not find conversation_id from contacts directly so we added this joins here. - def self.rebuild_pg_search_documents(account_id) - return super unless name == 'Conversation' - - connection.execute <<~SQL.squish - INSERT INTO pg_search_documents (searchable_type, searchable_id, content, account_id, conversation_id, inbox_id, created_at, updated_at) - SELECT 'Conversation' AS searchable_type, - conversations.id AS searchable_id, - CONCAT_WS(' ', conversations.display_id, contacts.email, contacts.name, contacts.phone_number, conversations.account_id) AS content, - conversations.account_id::int AS account_id, - conversations.id::int AS conversation_id, - conversations.inbox_id::int AS inbox_id, - now() AS created_at, - now() AS updated_at - FROM conversations - INNER JOIN contacts - ON conversations.contact_id = contacts.id - WHERE conversations.account_id = #{account_id} - SQL - end - private def execute_after_update_commit_callbacks