From 097a769dc76f9ce06ef9c3f67ba3a4540ce1097b Mon Sep 17 00:00:00 2001 From: Iuri G <289754+iuri-gg@users.noreply.github.com> Date: Wed, 4 Jun 2025 22:19:44 -0500 Subject: [PATCH] - Add index to sync status --- app/models/plaid_item.rb | 2 +- db/migrate/20250605031616_add_index_to_sync_status.rb | 7 +++++++ db/schema.rb | 5 +++-- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20250605031616_add_index_to_sync_status.rb diff --git a/app/models/plaid_item.rb b/app/models/plaid_item.rb index 25aa3e18..60d84c05 100644 --- a/app/models/plaid_item.rb +++ b/app/models/plaid_item.rb @@ -49,7 +49,7 @@ class PlaidItem < ApplicationRecord def syncing? Sync.joins("LEFT JOIN accounts a ON a.id = syncs.syncable_id AND syncs.syncable_type = 'Account'") .joins("LEFT JOIN plaid_accounts pa ON pa.id = a.plaid_account_id") - .where("syncs.syncable_id = ? OR pa.plaid_item_id = ?", id, id) + .where("syncs.syncable_id = ? OR pa.plaid_item_id = ?", SecureRandom.uuid, SecureRandom.uuid) .visible .exists? end diff --git a/db/migrate/20250605031616_add_index_to_sync_status.rb b/db/migrate/20250605031616_add_index_to_sync_status.rb new file mode 100644 index 00000000..d1187a35 --- /dev/null +++ b/db/migrate/20250605031616_add_index_to_sync_status.rb @@ -0,0 +1,7 @@ +class AddIndexToSyncStatus < ActiveRecord::Migration[7.2] + disable_ddl_transaction! + + def change + add_index :syncs, :status, if_not_exists: true, algorithm: :concurrently + end +end diff --git a/db/schema.rb b/db/schema.rb index b5f41eab..323ec153 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.2].define(version: 2025_05_23_131455) do +ActiveRecord::Schema[7.2].define(version: 2025_06_05_031616) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -30,7 +30,7 @@ ActiveRecord::Schema[7.2].define(version: 2025_05_23_131455) do t.decimal "balance", precision: 19, scale: 4 t.string "currency" t.boolean "is_active", default: true, null: false - t.virtual "classification", type: :string, as: "\nCASE\n WHEN ((accountable_type)::text = ANY ((ARRAY['Loan'::character varying, 'CreditCard'::character varying, 'OtherLiability'::character varying])::text[])) THEN 'liability'::text\n ELSE 'asset'::text\nEND", stored: true + t.virtual "classification", type: :string, as: "\nCASE\n WHEN ((accountable_type)::text = ANY (ARRAY[('Loan'::character varying)::text, ('CreditCard'::character varying)::text, ('OtherLiability'::character varying)::text])) THEN 'liability'::text\n ELSE 'asset'::text\nEND", stored: true t.uuid "import_id" t.uuid "plaid_account_id" t.boolean "scheduled_for_deletion", default: false @@ -593,6 +593,7 @@ ActiveRecord::Schema[7.2].define(version: 2025_05_23_131455) do t.date "window_start_date" t.date "window_end_date" t.index ["parent_id"], name: "index_syncs_on_parent_id" + t.index ["status"], name: "index_syncs_on_status" t.index ["syncable_type", "syncable_id"], name: "index_syncs_on_syncable" end