perf: Add database index on conversations identifier (#12715)
**Problem** Slack webhook processing was failing with 500 errors due to database timeouts. The query `Conversation.where(identifier: params[:event][:thread_ts]).first` was performing full table scans and hitting PostgreSQL statement timeout. **Solution** Added database index on conversations.identifier and account_id.
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
class AddIndexToConversationsIdentifier < ActiveRecord::Migration[7.1]
|
||||||
|
disable_ddl_transaction!
|
||||||
|
def change
|
||||||
|
add_index :conversations, [:identifier, :account_id], name: 'index_conversations_on_identifier_and_account_id', algorithm: :concurrently
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.1].define(version: 2025_10_03_091242) do
|
ActiveRecord::Schema[7.1].define(version: 2025_10_22_152158) do
|
||||||
# These extensions should be enabled to support this database
|
# These extensions should be enabled to support this database
|
||||||
enable_extension "pg_stat_statements"
|
enable_extension "pg_stat_statements"
|
||||||
enable_extension "pg_trgm"
|
enable_extension "pg_trgm"
|
||||||
@@ -676,6 +676,7 @@ ActiveRecord::Schema[7.1].define(version: 2025_10_03_091242) do
|
|||||||
t.index ["contact_id"], name: "index_conversations_on_contact_id"
|
t.index ["contact_id"], name: "index_conversations_on_contact_id"
|
||||||
t.index ["contact_inbox_id"], name: "index_conversations_on_contact_inbox_id"
|
t.index ["contact_inbox_id"], name: "index_conversations_on_contact_inbox_id"
|
||||||
t.index ["first_reply_created_at"], name: "index_conversations_on_first_reply_created_at"
|
t.index ["first_reply_created_at"], name: "index_conversations_on_first_reply_created_at"
|
||||||
|
t.index ["identifier", "account_id"], name: "index_conversations_on_identifier_and_account_id"
|
||||||
t.index ["inbox_id"], name: "index_conversations_on_inbox_id"
|
t.index ["inbox_id"], name: "index_conversations_on_inbox_id"
|
||||||
t.index ["priority"], name: "index_conversations_on_priority"
|
t.index ["priority"], name: "index_conversations_on_priority"
|
||||||
t.index ["status", "account_id"], name: "index_conversations_on_status_and_account_id"
|
t.index ["status", "account_id"], name: "index_conversations_on_status_and_account_id"
|
||||||
|
|||||||
Reference in New Issue
Block a user