Skip to content

Commit 60205f8

Browse files
committed
fix: prevent resolve_bracket_bye from marking multi-feeder brackets as byes
Brackets with 2+ total feeders (like LB R1 with two WB R1 feeders) are designed to receive 2 teams through normal match play. They should never be treated as runtime byes. Only brackets with 0-1 feeders (from pruned LB R1 matches) are genuine runtime byes. This was causing LB R1 matches in 8-team DE brackets to be incorrectly marked as byes when both WB R1 feeder matches finished in quick succession.
1 parent 7af0cda commit 60205f8

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

hasura/functions/tournaments/resolve_bracket_bye.sql

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ CREATE OR REPLACE FUNCTION public.resolve_bracket_bye(
1111
AS $$
1212
DECLARE
1313
current_bracket tournament_brackets%ROWTYPE;
14+
total_feeders int;
1415
pending_feeders int;
1516
lone_team_id uuid;
1617
tournament_id uuid;
@@ -37,7 +38,19 @@ BEGIN
3738
RETURN false;
3839
END IF;
3940

40-
-- Count unfinished, non-bye feeder brackets that could still send a team
41+
-- A bracket with 2+ total feeders is designed to receive 2 teams through
42+
-- normal match play (e.g. LB R1 fed by two WB R1 matches). It should
43+
-- never be a bye — the second team will arrive when the other feeder finishes.
44+
SELECT COUNT(*) INTO total_feeders
45+
FROM tournament_brackets child
46+
WHERE child.parent_bracket_id = current_bracket.id
47+
OR child.loser_parent_bracket_id = current_bracket.id;
48+
49+
IF total_feeders >= 2 THEN
50+
RETURN false;
51+
END IF;
52+
53+
-- For brackets with 0-1 feeders, check if any are still pending
4154
SELECT COUNT(*) INTO pending_feeders
4255
FROM tournament_brackets child
4356
WHERE (child.parent_bracket_id = current_bracket.id

0 commit comments

Comments
 (0)