codeclimate fix

This commit is contained in:
Tejaswini Chile 2022-12-23 17:16:02 +05:30
parent 5bb54794d8
commit ca7e912c04
2 changed files with 24 additions and 22 deletions

View file

@ -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

View file

@ -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