Add eager loading for user and shop relationships in crypto_watcher

- Add joinedload for user and shop in all CryptoPayment queries
- Import sqlalchemy for ORM operations
- Ensures user display_name/username shows in payment logs
- Fixes missing user information in crypto_watcher logs
This commit is contained in:
Russell Ballestrini 2025-10-01 12:54:42 -04:00
parent 667b8fee50
commit c525cf4ecc

View file

@ -8,6 +8,7 @@ from typing import List
from decimal import Decimal
from urllib.parse import urlparse
import sqlalchemy as sa
from pyramid.paster import bootstrap, setup_logging
from .crypto_clients import get_client_from_settings, get_dogecoin_client_from_settings
@ -2997,6 +2998,10 @@ def process_refund_confirmations(request, settings):
# Query payments that need refund confirmation monitoring OR retry
refund_queue = (
db.query(CryptoPayment)
.options(
sa.orm.joinedload(CryptoPayment.user),
sa.orm.joinedload(CryptoPayment.shop),
)
.filter(
CryptoPayment.status.in_(
[
@ -3548,6 +3553,10 @@ def scan_wallet_for_double_or_late_payments(request, settings):
# Look up payment by subaddress
payment = (
db.query(CryptoPayment)
.options(
sa.orm.joinedload(CryptoPayment.user),
sa.orm.joinedload(CryptoPayment.shop),
)
.filter(
CryptoPayment.coin_type == coin_type,
CryptoPayment.account_index == account_idx,
@ -3729,6 +3738,10 @@ def scan_wallet_for_double_or_late_payments(request, settings):
# Look up payment by address
payment = (
db.query(CryptoPayment)
.options(
sa.orm.joinedload(CryptoPayment.user),
sa.orm.joinedload(CryptoPayment.shop),
)
.filter(
CryptoPayment.coin_type == coin_type,
CryptoPayment.address == tx.get("address"),
@ -3910,6 +3923,10 @@ def run_once(env, interval):
q = (
db.query(CryptoPayment)
.options(
sa.orm.joinedload(CryptoPayment.user),
sa.orm.joinedload(CryptoPayment.shop),
)
.filter(
CryptoPayment.status.in_(all_monitored_statuses),
CryptoPayment.swept_tx_hash.is_(