Skip to content

Commit b8a4f6e

Browse files
committed
🐛 fix: concurrency control in update_all_users_in_database function
1 parent 62d630f commit b8a4f6e

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

app/handler/user.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,14 @@ async def upsert_users_rating_and_attended_contests_count(
6666

6767

6868
@exception_logger_reraise
69-
async def update_all_users_in_database(batch_size: int = 100) -> None:
69+
async def update_all_users_in_database(
70+
batch_size: int = 100,
71+
) -> None:
72+
"""
73+
For all users in the User collection, update their rating and attended_contests_count.
74+
:param batch_size:
75+
:return:
76+
"""
7077
total_count = await User.count()
7178
logger.info(f"User collection now has {total_count=}")
7279
for i in range(0, total_count, batch_size):
@@ -96,11 +103,11 @@ async def update_all_users_in_database(batch_size: int = 100) -> None:
96103
)
97104
await gather_with_limited_concurrency(
98105
[
99-
# US site has a strong rate limit
100-
gather_with_limited_concurrency(cn_tasks, 20),
101-
gather_with_limited_concurrency(us_tasks, 5),
106+
# CN site has a strong rate limit
107+
gather_with_limited_concurrency(cn_tasks, 4),
108+
gather_with_limited_concurrency(us_tasks, 25),
102109
],
103-
25,
110+
30,
104111
)
105112

106113

@@ -173,9 +180,9 @@ async def save_users_of_contest(
173180
)
174181
await gather_with_limited_concurrency(
175182
[
176-
# US site has a strong rate limit
177-
gather_with_limited_concurrency(cn_tasks, 20),
178-
gather_with_limited_concurrency(us_tasks, 5),
179-
25,
183+
# CN site has a strong rate limit
184+
gather_with_limited_concurrency(cn_tasks, 4),
185+
gather_with_limited_concurrency(us_tasks, 25),
186+
30,
180187
],
181188
)

0 commit comments

Comments
 (0)