06/05 Optimize app: implement Plaid
This commit is contained in:
+12
-3
@@ -61,11 +61,12 @@ def index():
|
||||
|
||||
from app.models.teller_enrollment import TellerAccount
|
||||
from app.models.schwab_connection import SchwabAccount
|
||||
from app.models.plaid_item import PlaidAccount
|
||||
all_accounts = Account.query.filter_by(is_active=True).order_by(Account.name).all()
|
||||
pfm_ids = [a.id for a in all_accounts]
|
||||
|
||||
# Build sync-provider maps before the calc_balance loop.
|
||||
# Accounts linked to Teller or Schwab get their balance from the provider,
|
||||
# Accounts linked to Teller, Schwab, or Plaid get their balance from the provider,
|
||||
# not from transaction summation, so we skip calc_balance for them.
|
||||
teller_accounts = TellerAccount.query.filter(
|
||||
TellerAccount.pfm_account_id.in_(pfm_ids),
|
||||
@@ -79,7 +80,13 @@ def index():
|
||||
).all()
|
||||
schwab_map = {sa.pfm_account_id: sa for sa in schwab_accounts}
|
||||
|
||||
provider_ids = set(teller_map) | set(schwab_map)
|
||||
plaid_accounts = PlaidAccount.query.filter(
|
||||
PlaidAccount.pfm_account_id.in_(pfm_ids),
|
||||
PlaidAccount.is_active == True,
|
||||
).all()
|
||||
plaid_map = {pa.pfm_account_id: pa for pa in plaid_accounts}
|
||||
|
||||
provider_ids = set(teller_map) | set(schwab_map) | set(plaid_map)
|
||||
for a in all_accounts:
|
||||
if a.id not in provider_ids:
|
||||
calc_balance(a.id)
|
||||
@@ -111,7 +118,9 @@ def index():
|
||||
credit_count=len(credit_accounts),
|
||||
monthly_charges=monthly_charges,
|
||||
teller_map=teller_map,
|
||||
schwab_map=schwab_map)
|
||||
schwab_map=schwab_map,
|
||||
plaid_map=plaid_map,
|
||||
today=date.today())
|
||||
|
||||
|
||||
@accounts_bp.route('/new', methods=['GET', 'POST'])
|
||||
|
||||
Reference in New Issue
Block a user