diff --git a/app/models/conversation_with_label.rb b/app/models/conversation_with_label.rb index 2dc225299..9e3208c52 100644 --- a/app/models/conversation_with_label.rb +++ b/app/models/conversation_with_label.rb @@ -29,12 +29,11 @@ # # Indexes # -# index_conversation_with_labels_on_account_id (account_id) +# idx_conv_labels_view__acc_id__status__last_activity (account_id,status,last_activity_at) # index_conversation_with_labels_on_custom_attributes (custom_attributes) USING gin # index_conversation_with_labels_on_id (id) UNIQUE # index_conversation_with_labels_on_labels_array (labels_array) USING gin # index_conversation_with_labels_on_last_activity_at (last_activity_at) -# index_conversation_with_labels_on_status (status) # class ConversationWithLabel < ApplicationRecord def self.refresh diff --git a/db/migrate/20230602123133_add_index_to_conversation_with_labels_view.rb b/db/migrate/20230602123133_add_index_to_conversation_with_labels_view.rb index 4d476dd67..f05069919 100644 --- a/db/migrate/20230602123133_add_index_to_conversation_with_labels_view.rb +++ b/db/migrate/20230602123133_add_index_to_conversation_with_labels_view.rb @@ -4,8 +4,8 @@ class AddIndexToConversationWithLabelsView < ActiveRecord::Migration[7.0] def change # needs atleast one unuque index for concurrent refresh add_index :conversation_with_labels, :id, unique: true, algorithm: :concurrently - add_index :conversation_with_labels, :account_id, algorithm: :concurrently - add_index :conversation_with_labels, :status, algorithm: :concurrently + add_index :conversation_with_labels, [:account_id, :status, :last_activity_at], algorithm: :concurrently, + name: 'idx_conv_labels_view__acc_id__status__last_activity' add_index :conversation_with_labels, :custom_attributes, using: :gin, algorithm: :concurrently add_index :conversation_with_labels, :labels_array, using: :gin, algorithm: :concurrently add_index :conversation_with_labels, :last_activity_at, order: { last_activity_at: :desc }, algorithm: :concurrently diff --git a/db/schema.rb b/db/schema.rb index 21d6e7fa7..3ef0ccc60 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -966,12 +966,11 @@ ActiveRecord::Schema[7.0].define(version: 2023_06_02_123133) do LEFT JOIN tags ON ((tags.id = taggings.tag_id))) GROUP BY conversations.id; SQL - add_index "conversation_with_labels", ["account_id"], name: "index_conversation_with_labels_on_account_id" + add_index "conversation_with_labels", ["account_id", "status", "last_activity_at"], name: "idx_conv_labels_view__acc_id__status__last_activity" add_index "conversation_with_labels", ["custom_attributes"], name: "index_conversation_with_labels_on_custom_attributes", using: :gin add_index "conversation_with_labels", ["id"], name: "index_conversation_with_labels_on_id", unique: true add_index "conversation_with_labels", ["labels_array"], name: "index_conversation_with_labels_on_labels_array", using: :gin add_index "conversation_with_labels", ["last_activity_at"], name: "index_conversation_with_labels_on_last_activity_at", order: :desc - add_index "conversation_with_labels", ["status"], name: "index_conversation_with_labels_on_status" create_trigger("accounts_after_insert_row_tr", :generated => true, :compatibility => 1). on("accounts").