From fae84225082fb42f34e751d5292ef10e53bf4168 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Sun, 5 May 2024 22:43:41 -0500 Subject: [PATCH] Dirty cache when rating --- judge/caching.py | 9 +++++++++ judge/ratings.py | 3 +++ 2 files changed, 12 insertions(+) diff --git a/judge/caching.py b/judge/caching.py index 8fd40df..66ea686 100644 --- a/judge/caching.py +++ b/judge/caching.py @@ -83,8 +83,17 @@ def cache_wrapper(prefix, timeout=None): if result is not None: _set_l0(key, result) + def dirty_multi(args_list): + keys = [] + for args in args_list: + keys.append(get_key(func, *args)) + cache.delete_many(keys) + if l0_cache: + l0_cache.delete_many(keys) + wrapper.dirty = dirty wrapper.prefetch_multi = prefetch_multi + wrapper.dirty_multi = dirty_multi return wrapper diff --git a/judge/ratings.py b/judge/ratings.py index de2c313..f255e31 100644 --- a/judge/ratings.py +++ b/judge/ratings.py @@ -146,6 +146,7 @@ def recalculate_ratings(ranking, old_mean, times_ranked, historical_p): def rate_contest(contest): from judge.models import Rating, Profile + from judge.models.profile import _get_basic_info rating_subquery = Rating.objects.filter(user=OuterRef("user")) rating_sorted = rating_subquery.order_by("-contest__end_time") @@ -237,6 +238,8 @@ def rate_contest(contest): ) ) + _get_basic_info.dirty_multi([(uid,) for uid in user_ids]) + RATING_LEVELS = [ "Newbie",