def get_all_contest_participants_detail(contest: Contest, users=None, privilege=False):
cache_template = PARTICIPANT_RANK_DETAIL_PRIVATE if privilege else PARTICIPANT_RANK_DETAIL
timeout = 60 if privilege else FORTNIGHT
contest_users = users if users else contest.participants_ids
cache_names = list(map(lambda x: cache_template.format(contest=contest.pk, user=x), contest_users))
cache_res = cache.get_many(cache_names)
ans = dict()
second_attempt = []
for user in contest_users:
cache_name = cache_template.format(contest=contest.pk, user=user)
if cache_name not in cache_res.keys():
second_attempt.append(user)
else:
ans[user] = cache_res[cache_name]
if second_attempt:
ans2 = recalculate_for_participants(contest, second_attempt, privilege)
cache.set_many({cache_template.format(contest=contest.pk, user=user_id): val for user_id, val in ans2.items()},
timeout * uniform(0.8, 1))
ans.update(ans2)
return ans
评论列表
文章目录