Skip to content

Commit

Permalink
🐛 fix: reduce concurrency to address issues with updating Contest, Qu…
Browse files Browse the repository at this point in the history
…estion and User collections
  • Loading branch information
baoliay2008 committed Mar 11, 2024
1 parent 9a8939b commit f8e7dcd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
8 changes: 6 additions & 2 deletions app/handler/contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
)
from app.crawler.utils import multi_http_request
from app.db.models import Contest
from app.utils import exception_logger_reraise, exception_logger_silence
from app.utils import (
exception_logger_reraise,
exception_logger_silence,
gather_with_limited_concurrency,
)


async def multi_upsert_contests(
Expand Down Expand Up @@ -54,7 +58,7 @@ async def multi_upsert_contests(
on_insert=contest,
)
)
await asyncio.gather(*tasks)
await gather_with_limited_concurrency(tasks)
logger.success("finished")


Expand Down
8 changes: 4 additions & 4 deletions app/handler/question.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from app.crawler.question import request_question_list
from app.db.models import Question, Submission
from app.utils import get_contest_start_time
from app.utils import gather_with_limited_concurrency, get_contest_start_time


async def real_time_count_at_time_point(
Expand Down Expand Up @@ -49,13 +49,13 @@ async def save_questions_real_time_count(
Question.contest_name == contest_name,
).to_list()
for question in questions:
tasks = (
tasks = [
real_time_count_at_time_point(
contest_name, question.question_id, time_point
)
for time_point in time_series
)
question.real_time_count = await asyncio.gather(*tasks)
]
question.real_time_count = await gather_with_limited_concurrency(tasks)
await question.save()
logger.success("finished")

Expand Down
2 changes: 1 addition & 1 deletion app/handler/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,6 @@ async def save_users_of_contest(
[
# CN site has a strong rate limit
gather_with_limited_concurrency(cn_tasks, 1),
gather_with_limited_concurrency(us_tasks, 8),
gather_with_limited_concurrency(us_tasks, 1),
],
)

0 comments on commit f8e7dcd

Please sign in to comment.