feat: add index to conversation id and account_id (#6757)

- This PR adds an index to conversations id and account_id. This improves the performance of some reports query
This commit is contained in:
Shivam Mishra
2023-03-28 22:34:04 +05:30
committed by GitHub
parent 54a809ea54
commit bc8e8f3bb5
6 changed files with 27 additions and 1 deletions

View File

@@ -165,6 +165,10 @@ group :development do
# When we want to squash migrations
gem 'squasher'
# profiling
gem 'rack-mini-profiler', require: false
gem 'stackprof'
end
group :test do

View File

@@ -520,6 +520,8 @@ GEM
rack (>= 1.0, < 3)
rack-cors (1.1.1)
rack (>= 2.0.0)
rack-mini-profiler (3.0.0)
rack (>= 1.2.0)
rack-protection (3.0.5)
rack
rack-proxy (0.7.2)
@@ -692,6 +694,7 @@ GEM
activesupport (>= 5.2)
sprockets (>= 3.0.0)
squasher (0.6.2)
stackprof (0.2.24)
statsd-ruby (1.5.0)
stripe (6.5.0)
telephone_number (1.4.16)
@@ -840,6 +843,7 @@ DEPENDENCIES
pundit
rack-attack
rack-cors
rack-mini-profiler
rack-timeout
rails (~> 6.1, >= 6.1.7.3)
redis
@@ -865,6 +869,7 @@ DEPENDENCIES
spring
spring-watcher-listen
squasher
stackprof
stripe
telephone_number
test-prof

View File

@@ -35,6 +35,7 @@
# index_conversations_on_contact_id (contact_id)
# index_conversations_on_contact_inbox_id (contact_inbox_id)
# index_conversations_on_first_reply_created_at (first_reply_created_at)
# index_conversations_on_id_and_account_id (account_id,id)
# index_conversations_on_inbox_id (inbox_id)
# index_conversations_on_last_activity_at (last_activity_at)
# index_conversations_on_status_and_account_id (status,account_id)

View File

@@ -0,0 +1,8 @@
# frozen_string_literal: true
if Rails.env.development?
require 'rack-mini-profiler'
# initialization is skipped so trigger it
Rack::MiniProfilerRails.initialize!(Rails.application)
end

View File

@@ -0,0 +1,7 @@
class AddIndexToConversationsAccountIdAndId < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
def change
add_index :conversations, [:account_id, :id], name: 'index_conversations_on_id_and_account_id', algorithm: :concurrently
end
end

View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2023_03_15_105847) do
ActiveRecord::Schema.define(version: 2023_03_27_081350) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
@@ -448,6 +448,7 @@ ActiveRecord::Schema.define(version: 2023_03_15_105847) do
t.datetime "assignee_last_seen_at"
t.datetime "first_reply_created_at"
t.index ["account_id", "display_id"], name: "index_conversations_on_account_id_and_display_id", unique: true
t.index ["account_id", "id"], name: "index_conversations_on_id_and_account_id"
t.index ["account_id", "inbox_id", "status", "assignee_id"], name: "conv_acid_inbid_stat_asgnid_idx"
t.index ["account_id"], name: "index_conversations_on_account_id"
t.index ["assignee_id", "account_id"], name: "index_conversations_on_assignee_id_and_account_id"