Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Settle whole tip graph. fixes #2664
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitpaulk committed Nov 9, 2014
1 parent 5a78c15 commit 7105d6d
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions gratipay/billing/payday.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7105d6d

Please sign in to comment.