From 42e9c1f806b7f4411411c1a980ba18e72112ed00 Mon Sep 17 00:00:00 2001 From: Vincent Pochet Date: Fri, 20 Dec 2024 17:17:41 +0100 Subject: [PATCH] misc(CachedAggregation): Add index with external_subscription_id --- app/models/cached_aggregation.rb | 1 + .../20241220160748_index_cached_aggregation.rb | 12 ++++++++++++ db/schema.rb | 1 + 3 files changed, 14 insertions(+) create mode 100644 db/migrate/20241220160748_index_cached_aggregation.rb diff --git a/app/models/cached_aggregation.rb b/app/models/cached_aggregation.rb index e004e7754b8..36c3f15b6ef 100644 --- a/app/models/cached_aggregation.rb +++ b/app/models/cached_aggregation.rb @@ -36,6 +36,7 @@ class CachedAggregation < ApplicationRecord # # Indexes # +# idx_on_timestamp_charge_id_external_subscription_id (timestamp,charge_id,external_subscription_id) # index_cached_aggregations_on_charge_id (charge_id) # index_cached_aggregations_on_event_id (event_id) # index_cached_aggregations_on_event_transaction_id (organization_id,event_transaction_id) diff --git a/db/migrate/20241220160748_index_cached_aggregation.rb b/db/migrate/20241220160748_index_cached_aggregation.rb new file mode 100644 index 00000000000..4de2c4f4efe --- /dev/null +++ b/db/migrate/20241220160748_index_cached_aggregation.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class IndexCachedAggregation < ActiveRecord::Migration[7.1] + disable_ddl_transaction! + + def change + add_index :cached_aggregations, + %i[timestamp charge_id external_subscription_id], + algorithm: :concurrently, + name: :idx_on_timestamp_charge_id_external_subscription_id + end +end diff --git a/db/schema.rb b/db/schema.rb index ae8eed314aa..b3228c8e2c8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -229,6 +229,7 @@ t.index ["organization_id", "timestamp", "charge_id", "group_id"], name: "index_timestamp_group_lookup" t.index ["organization_id", "timestamp", "charge_id"], name: "index_timestamp_lookup" t.index ["organization_id"], name: "index_cached_aggregations_on_organization_id" + t.index ["timestamp", "charge_id", "external_subscription_id"], name: "idx_on_timestamp_charge_id_external_subscription_id" end create_table "charge_filter_values", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|