Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

added collect_health_stats to enablebanking syncer (#1390)

Neeraj Vermadf2863ea7be0
diff --git a/app/models/enable_banking_item/syncer.rb b/app/models/enable_banking_item/syncer.rb
index 7ab6e82799..dfe8ce9841 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