mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-06 05:55:21 +02:00
Add tagged logging to sync process (#1956)
* Add tagged logging to sync process * Reduce logging in syncer * Typo
This commit is contained in:
parent
cffafd23f0
commit
9627a6bf6f
6 changed files with 86 additions and 39 deletions
|
@ -5,13 +5,16 @@ class Account::BalanceCalculator
|
|||
end
|
||||
|
||||
def calculate(reverse: false, start_date: nil)
|
||||
cash_balances = reverse ? reverse_cash_balances : forward_cash_balances
|
||||
Rails.logger.tagged("Account::BalanceCalculator") do
|
||||
Rails.logger.info("Calculating cash balances with strategy: #{reverse ? "reverse sync" : "forward sync"}")
|
||||
cash_balances = reverse ? reverse_cash_balances : forward_cash_balances
|
||||
|
||||
cash_balances.map do |balance|
|
||||
holdings_value = converted_holdings.select { |h| h.date == balance.date }.sum(&:amount)
|
||||
balance.balance = balance.balance + holdings_value
|
||||
balance
|
||||
end.compact
|
||||
cash_balances.map do |balance|
|
||||
holdings_value = converted_holdings.select { |h| h.date == balance.date }.sum(&:amount)
|
||||
balance.balance = balance.balance + holdings_value
|
||||
balance
|
||||
end.compact
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -5,9 +5,14 @@ class Account::HoldingCalculator
|
|||
end
|
||||
|
||||
def calculate(reverse: false)
|
||||
preload_securities
|
||||
calculated_holdings = reverse ? reverse_holdings : forward_holdings
|
||||
gapfill_holdings(calculated_holdings)
|
||||
Rails.logger.tagged("Account::HoldingCalculator") do
|
||||
preload_securities
|
||||
|
||||
Rails.logger.info("Calculating holdings with strategy: #{reverse ? "reverse sync" : "forward sync"}")
|
||||
calculated_holdings = reverse ? reverse_holdings : forward_holdings
|
||||
|
||||
gapfill_holdings(calculated_holdings)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -5,19 +5,34 @@ class Account::Syncer
|
|||
end
|
||||
|
||||
def run
|
||||
account.family.auto_match_transfers!
|
||||
Rails.logger.tagged("Account::Syncer") do
|
||||
Rails.logger.info("Finding potential transfers to auto-match")
|
||||
account.family.auto_match_transfers!
|
||||
|
||||
holdings = sync_holdings
|
||||
balances = sync_balances(holdings)
|
||||
account.reload
|
||||
update_account_info(balances, holdings) unless plaid_sync?
|
||||
convert_records_to_family_currency(balances, holdings) unless account.currency == account.family.currency
|
||||
holdings = sync_holdings
|
||||
Rails.logger.info("Calculated #{holdings.size} holdings")
|
||||
|
||||
# Enrich if user opted in or if we're syncing transactions from a Plaid account on the hosted app
|
||||
if account.family.data_enrichment_enabled? || (plaid_sync? && Rails.application.config.app_mode.hosted?)
|
||||
account.enrich_data
|
||||
else
|
||||
Rails.logger.info("Data enrichment is disabled, skipping enrichment for account #{account.id}")
|
||||
balances = sync_balances(holdings)
|
||||
Rails.logger.info("Calculated #{balances.size} balances")
|
||||
|
||||
account.reload
|
||||
|
||||
unless plaid_sync?
|
||||
update_account_info(balances, holdings)
|
||||
end
|
||||
|
||||
unless account.currency == account.family.currency
|
||||
Rails.logger.info("Converting #{balances.size} balances and #{holdings.size} holdings from #{account.currency} to #{account.family.currency}")
|
||||
convert_records_to_family_currency(balances, holdings)
|
||||
end
|
||||
|
||||
# Enrich if user opted in or if we're syncing transactions from a Plaid account on the hosted app
|
||||
if account.family.data_enrichment_enabled? || (plaid_sync? && Rails.application.config.app_mode.hosted?)
|
||||
Rails.logger.info("Enriching transaction data for account #{account.name}")
|
||||
account.enrich_data
|
||||
else
|
||||
Rails.logger.info("Data enrichment disabled for account #{account.name}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -43,8 +58,6 @@ class Account::Syncer
|
|||
calculator = Account::HoldingCalculator.new(account)
|
||||
calculated_holdings = calculator.calculate(reverse: plaid_sync?)
|
||||
|
||||
current_time = Time.now
|
||||
|
||||
Account.transaction do
|
||||
load_holdings(calculated_holdings)
|
||||
purge_outdated_holdings unless plaid_sync?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue