From df2863ea7be0fa69b3e2b7905aaa83c5b1239f42 Mon Sep 17 00:00:00 2001 From: Neeraj Verma Date: Tue, 7 Apr 2026 09:43:57 +0100 Subject: [PATCH] added collect_health_stats to enablebanking syncer (#1390) Also made improvements to linked_accounts query --- app/models/enable_banking_item/syncer.rb | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/app/models/enable_banking_item/syncer.rb b/app/models/enable_banking_item/syncer.rb index 7ab6e8279..dfe8ce984 100644 --- a/app/models/enable_banking_item/syncer.rb +++ b/app/models/enable_banking_item/syncer.rb @@ -34,11 +34,6 @@ class EnableBankingItem::Syncer sync.update!(status_text: "Checking account configuration...") if sync.respond_to?(:status_text) collect_setup_stats(sync, provider_accounts: enable_banking_item.enable_banking_accounts.includes(:account_provider, :account)) - linked_accounts = enable_banking_item.enable_banking_accounts - .joins(:account_provider) - .includes(:account_provider, :account) - .joins(:account) - .merge(Account.visible) unlinked_accounts = enable_banking_item.enable_banking_accounts.left_joins(:account_provider).where(account_providers: { id: nil }) if unlinked_accounts.any? @@ -49,13 +44,18 @@ class EnableBankingItem::Syncer end # Phase 3: Process transactions for linked and visible accounts only - if linked_accounts.any? + linked_account_ids = enable_banking_item.enable_banking_accounts + .joins(:account_provider) + .joins(:account) + .merge(Account.visible) + .pluck("accounts.id") + + if linked_account_ids.any? sync.update!(status_text: "Processing transactions...") if sync.respond_to?(:status_text) - account_ids = linked_accounts.filter_map { |a| a.current_account&.id } enable_banking_item.process_accounts # Collect transaction statistics - collect_transaction_stats(sync, account_ids: account_ids, source: "enable_banking") + collect_transaction_stats(sync, account_ids: linked_account_ids, source: "enable_banking") # Phase 4: Schedule balance calculations for linked accounts sync.update!(status_text: "Calculating balances...") if sync.respond_to?(:status_text) @@ -65,6 +65,11 @@ class EnableBankingItem::Syncer window_end_date: sync.window_end_date ) end + + collect_health_stats(sync, errors: nil) + rescue => e + collect_health_stats(sync, errors: [ { message: e.message, category: "sync_error" } ]) + raise end def perform_post_sync