Skip to content

Commit

Permalink
feat(perf): add index to messages created at (#7044)
Browse files Browse the repository at this point in the history
* feat: add index to messages created at

* feat: run migration
  • Loading branch information
scmmishra committed May 10, 2023
1 parent 6137a45 commit 662967b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/models/message.rb
Expand Up @@ -27,6 +27,7 @@
# index_messages_on_additional_attributes_campaign_id (((additional_attributes -> 'campaign_id'::text))) USING gin
# index_messages_on_content (content) USING gin
# index_messages_on_conversation_id (conversation_id)
# index_messages_on_created_at (created_at)
# index_messages_on_inbox_id (inbox_id)
# index_messages_on_sender_type_and_sender_id (sender_type,sender_id)
# index_messages_on_source_id (source_id)
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20230509101256_add_index_to_messages_created_at.rb
@@ -0,0 +1,6 @@
class AddIndexToMessagesCreatedAt < ActiveRecord::Migration[7.0]
disable_ddl_transaction!
def change
add_index :messages, [:created_at], name: 'index_messages_on_created_at', algorithm: :concurrently
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_04_26_130150) do
ActiveRecord::Schema[7.0].define(version: 2023_05_09_101256) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
enable_extension "pg_trgm"
Expand Down Expand Up @@ -667,6 +667,7 @@
t.index ["account_id"], name: "index_messages_on_account_id"
t.index ["content"], name: "index_messages_on_content", opclass: :gin_trgm_ops, using: :gin
t.index ["conversation_id"], name: "index_messages_on_conversation_id"
t.index ["created_at"], name: "index_messages_on_created_at"
t.index ["inbox_id"], name: "index_messages_on_inbox_id"
t.index ["sender_type", "sender_id"], name: "index_messages_on_sender_type_and_sender_id"
t.index ["source_id"], name: "index_messages_on_source_id"
Expand Down

0 comments on commit 662967b

Please sign in to comment.