Skip to content
This repository was archived by the owner on Oct 18, 2020. It is now read-only.

Commit e991b83

Browse files
committed
seeding: use a composite list for bulk_add
1 parent bbb8afb commit e991b83

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

utils/seeding.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,22 @@ async def seed_participants(participants):
5656
except KeyError:
5757
participants[joueur]['elo'] = base_elo # base Elo if none found
5858

59-
# Sort!
59+
# Sort & clean & make a composite list (to avoid "414 Request-URI Too Large")
6060
sorted_participants = sorted(participants.items(), key=lambda k_v: k_v[1]['elo'], reverse=True)
6161
sorted_participants = [x[1]['display_name'] for x in sorted_participants]
62-
63-
# Send to Challonge
64-
challonge_participants = await async_http_retry(
65-
achallonge.participants.bulk_add,
66-
tournoi['id'],
67-
sorted_participants
68-
)
69-
70-
# Assign IDs
71-
for inscrit in challonge_participants:
72-
for joueur in participants:
73-
if inscrit['name'] == participants[joueur]['display_name']:
74-
participants[joueur]['challonge'] = inscrit['id']
75-
break
62+
sorted_participants = [sorted_participants[x:x+(50)] for x in range(0, len(sorted_participants),50)]
63+
64+
# Send to Challonge and assign IDs
65+
for chunk_participants in sorted_participants:
66+
67+
challonge_participants = await async_http_retry(
68+
achallonge.participants.bulk_add,
69+
tournoi['id'],
70+
chunk_participants
71+
)
72+
73+
for inscrit in challonge_participants:
74+
for joueur in participants:
75+
if inscrit['name'] == participants[joueur]['display_name']:
76+
participants[joueur]['challonge'] = inscrit['id']
77+
break

0 commit comments

Comments
 (0)