feat: update view indexes

This commit is contained in:
Shivam Mishra
2023-06-02 18:00:44 +05:30
parent 9470c00549
commit 534d0c3ac2
3 changed files with 22 additions and 2 deletions
+9
View File
@@ -27,6 +27,15 @@
# inbox_id :integer
# team_id :bigint
#
# Indexes
#
# index_conversation_with_labels_on_account_id (account_id)
# 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
# https://github.com/scenic-views/scenic#what-about-materialized-views
@@ -1,8 +1,12 @@
class CreateConversationWithLabels < ActiveRecord::Migration[7.0]
def change
create_view :conversation_with_labels
create_view :conversation_with_labels, materialized: true
add_index :conversation_with_labels, :id, unique: true
add_index :conversation_with_labels, :account_id
add_index :conversation_with_labels, :status
add_index :conversation_with_labels, :custom_attributes, using: :gin
add_index :conversation_with_labels, :labels_array, using: :gin
add_index :conversation_with_labels, :last_activity_at, order: { last_activity_at: :desc }
end
end
+8 -1
View File
@@ -936,7 +936,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_06_02_120613) do
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
add_foreign_key "inboxes", "portals"
create_view "conversation_with_labels", sql_definition: <<-SQL
create_view "conversation_with_labels", materialized: true, sql_definition: <<-SQL
SELECT conversations.id,
conversations.account_id,
conversations.inbox_id,
@@ -966,6 +966,13 @@ ActiveRecord::Schema[7.0].define(version: 2023_06_02_120613) 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", ["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").
after(:insert).