From 7105d6d0ded03ad36f3929a5e8a9bcbbb1b6d0d9 Mon Sep 17 00:00:00 2001 From: Rohit Paul Kuruvilla Date: Sun, 9 Nov 2014 16:11:13 +0530 Subject: [PATCH] Settle whole tip graph. fixes #2664 --- gratipay/billing/payday.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/gratipay/billing/payday.py b/gratipay/billing/payday.py index 0063642428..bd4f0c951a 100644 --- a/gratipay/billing/payday.py +++ b/gratipay/billing/payday.py @@ -185,6 +185,7 @@ def prepare(cursor, ts_start): , is_suspicious , goal , false AS card_hold_ok + , false AS discovered FROM participants WHERE is_suspicious IS NOT true AND claimed_time < %(ts_start)s @@ -286,6 +287,9 @@ def prepare(cursor, ts_start): ); IF (NEW.amount <= tipper.new_balance OR tipper.card_hold_ok) THEN EXECUTE transfer(NEW.tipper, NEW.tippee, NEW.amount, 'tip'); + UPDATE payday_participants + SET discovered = true + WHERE username = NEW.tippee; RETURN NEW; END IF; RETURN NULL; @@ -425,6 +429,27 @@ def transfer_tips(cursor): WHERE p.username = t.tipper AND p.card_hold_ok; + DO $$ DECLARE count integer; + BEGIN + LOOP + WITH updated_rows AS ( + UPDATE payday_tips t + SET is_funded = true + FROM payday_participants p + WHERE t.is_funded IS NOT true + AND p.username = t.tipper + AND p.discovered is true + RETURNING * + ) + SELECT COUNT(*) FROM updated_rows INTO count; + + IF count = 0 THEN + EXIT; + END IF; + END LOOP; + END; + $$ LANGUAGE plpgsql; + UPDATE payday_tips t SET is_funded = true WHERE is_funded IS NOT true;