From 16d581e612fc67f6fd2ba74de769a4fad6474ed0 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Tue, 23 Sep 2025 13:05:09 -0400 Subject: [PATCH] Use efficient database filtering for swept payments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- make_post_sell/lib/crypto_watcher.py | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/make_post_sell/lib/crypto_watcher.py b/make_post_sell/lib/crypto_watcher.py index 696f4eb..bc056ca 100644 --- a/make_post_sell/lib/crypto_watcher.py +++ b/make_post_sell/lib/crypto_watcher.py @@ -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()