Change indexes on quotes to efficiently list quotes of a given account or quoted status (#35819)

This commit is contained in:
Claire 2025-08-19 14:50:30 +02:00 committed by GitHub
parent 421dbf9a7f
commit 736751e5de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 3 deletions

View File

@ -0,0 +1,13 @@
# frozen_string_literal: true
class UpdateQuoteIndex < ActiveRecord::Migration[8.0]
disable_ddl_transaction!
def change
add_index :quotes, [:account_id, :quoted_account_id, :id], algorithm: :concurrently
remove_index :quotes, [:account_id, :quoted_account_id]
add_index :quotes, [:quoted_status_id, :id], algorithm: :concurrently
remove_index :quotes, [:quoted_status_id]
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.0].define(version: 2025_08_05_075010) do
ActiveRecord::Schema[8.0].define(version: 2025_08_19_100545) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"
@ -926,11 +926,11 @@ ActiveRecord::Schema[8.0].define(version: 2025_08_05_075010) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "legacy", default: false, null: false
t.index ["account_id", "quoted_account_id"], name: "index_quotes_on_account_id_and_quoted_account_id"
t.index ["account_id", "quoted_account_id", "id"], name: "index_quotes_on_account_id_and_quoted_account_id_and_id"
t.index ["activity_uri"], name: "index_quotes_on_activity_uri", unique: true, where: "(activity_uri IS NOT NULL)"
t.index ["approval_uri"], name: "index_quotes_on_approval_uri", where: "(approval_uri IS NOT NULL)"
t.index ["quoted_account_id"], name: "index_quotes_on_quoted_account_id"
t.index ["quoted_status_id"], name: "index_quotes_on_quoted_status_id"
t.index ["quoted_status_id", "id"], name: "index_quotes_on_quoted_status_id_and_id"
t.index ["status_id"], name: "index_quotes_on_status_id", unique: true
end