codeclimate fix
This commit is contained in:
parent
5bb54794d8
commit
ca7e912c04
2 changed files with 24 additions and 22 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue