From 534d0c3ac2d1db3e0a094f11eb8d287bd9a8b375 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Fri, 2 Jun 2023 18:00:44 +0530 Subject: [PATCH] feat: update view indexes --- app/models/conversation_with_label.rb | 9 +++++++++ .../20230602120613_create_conversation_with_labels.rb | 6 +++++- db/schema.rb | 9 ++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/models/conversation_with_label.rb b/app/models/conversation_with_label.rb index 3ae1858c2..db3dcda35 100644 --- a/app/models/conversation_with_label.rb +++ b/app/models/conversation_with_label.rb @@ -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 diff --git a/db/migrate/20230602120613_create_conversation_with_labels.rb b/db/migrate/20230602120613_create_conversation_with_labels.rb index fb0855e87..03084caee 100644 --- a/db/migrate/20230602120613_create_conversation_with_labels.rb +++ b/db/migrate/20230602120613_create_conversation_with_labels.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index b0af27ac6..a1213e6bd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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).