Use efficient database filtering for swept payments
- Filter at database level with swept_tx_hash.is_(None) for minimum result set - Remove artificial "swept" status - keep "confirmed" as final state - is_swept property derives from swept_tx_hash column, no separate boolean - Stuck payments with swept_tx_hash set will be automatically excluded 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
4ed53ba062
commit
16d581e612
1 changed files with 8 additions and 16 deletions
|
|
@ -641,11 +641,7 @@ def process_payment(
|
|||
)
|
||||
sweep_success = auto_sweep_payment(client, crypto_payment)
|
||||
if sweep_success and crypto_payment.is_swept:
|
||||
# Mark as finalized so it's excluded from future processing
|
||||
crypto_payment.status = "swept"
|
||||
logger.info(
|
||||
f"Payment {crypto_payment.id} swept successfully - marked as finalized"
|
||||
)
|
||||
logger.info(f"Payment {crypto_payment.id} swept successfully")
|
||||
else:
|
||||
logger.debug(
|
||||
f"Payment {crypto_payment.id} confirmed but funds not yet unlocked"
|
||||
|
|
@ -667,17 +663,13 @@ def run_once(env, interval):
|
|||
with request.tm:
|
||||
db = request.dbsession
|
||||
|
||||
q = (
|
||||
db.query(CryptoPayment)
|
||||
.filter(
|
||||
CryptoPayment.status.in_(
|
||||
["pending", "received", "confirmed", "confirmed_overpaid"]
|
||||
)
|
||||
)
|
||||
.filter(
|
||||
# Exclude payments that are already swept (finalized and done)
|
||||
CryptoPayment.swept_tx_hash.is_(None)
|
||||
)
|
||||
q = db.query(CryptoPayment).filter(
|
||||
CryptoPayment.status.in_(
|
||||
["pending", "received", "confirmed", "confirmed_overpaid"]
|
||||
),
|
||||
CryptoPayment.swept_tx_hash.is_(
|
||||
None
|
||||
), # Only process payments that are not swept
|
||||
)
|
||||
payments = q.all()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue