mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-25 08:09:38 +02:00
* add kind to transaction model * Basic transfer creator * Fix method naming conflict * Creator form pattern * Remove stale methods * Tweak migration * Remove BaseQuery, write entire query in each class for clarity * Query optimizations * Remove unused exchange rate query lines * Remove temporary cache-warming strategy * Fix test * Update transaction search * Decouple transactions endpoint from IncomeStatement * Clean up transactions controller * Update cursor rules * Cleanup comments, logic in search * Fix totals logic on transactions view * Fix pagination * Optimize search totals query * Default to last 30 days on transactions page if no filters * Decouple transactions list from transfer details * Revert transfer route * Migration reset * Bundle update * Fix matching logic, tests * Remove unused code
37 lines
1.2 KiB
Ruby
37 lines
1.2 KiB
Ruby
class Account::Syncer
|
|
attr_reader :account
|
|
|
|
def initialize(account)
|
|
@account = account
|
|
end
|
|
|
|
def perform_sync(sync)
|
|
Rails.logger.info("Processing balances (#{account.linked? ? 'reverse' : 'forward'})")
|
|
import_market_data
|
|
materialize_balances
|
|
end
|
|
|
|
def perform_post_sync
|
|
account.family.auto_match_transfers!
|
|
end
|
|
|
|
private
|
|
def materialize_balances
|
|
strategy = account.linked? ? :reverse : :forward
|
|
Balance::Materializer.new(account, strategy: strategy).materialize_balances
|
|
end
|
|
|
|
# Syncs all the exchange rates + security prices this account needs to display historical chart data
|
|
#
|
|
# This is a *supplemental* sync. The daily market data sync should have already populated
|
|
# a majority or all of this data, so this is often a no-op.
|
|
#
|
|
# We rescue errors here because if this operation fails, we don't want to fail the entire sync since
|
|
# we have reasonable fallbacks for missing market data.
|
|
def import_market_data
|
|
Account::MarketDataImporter.new(account).import_all
|
|
rescue => e
|
|
Rails.logger.error("Error syncing market data for account #{account.id}: #{e.message}")
|
|
Sentry.capture_exception(e)
|
|
end
|
|
end
|