mirror of
https://github.com/pretix/pretix.git
synced 2026-05-06 15:24:02 +00:00
Fix cache invalidation
This commit is contained in:
@@ -43,6 +43,7 @@ from typing import Optional, Tuple
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
import dateutil.parser
|
||||
import django_redis
|
||||
from dateutil.tz import datetime_exists
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ValidationError
|
||||
@@ -57,7 +58,6 @@ from django.utils.functional import cached_property
|
||||
from django.utils.timezone import is_naive, make_aware, now
|
||||
from django.utils.translation import gettext_lazy as _, pgettext_lazy
|
||||
from django_countries.fields import Country
|
||||
from django_redis import get_redis_connection
|
||||
from django_scopes import ScopedManager
|
||||
from i18nfield.fields import I18nCharField, I18nTextField
|
||||
|
||||
@@ -1910,8 +1910,13 @@ class Quota(LoggedModel):
|
||||
|
||||
def rebuild_cache(self, now_dt=None):
|
||||
if settings.HAS_REDIS:
|
||||
rc = get_redis_connection("redis")
|
||||
rc.hdel(f'quotas:{self.event_id}:availabilitycache', str(self.pk))
|
||||
rc = django_redis.get_redis_connection("redis")
|
||||
p = rc.pipeline()
|
||||
p.hdel(f'quotas:{self.event_id}:availabilitycache', str(self.pk))
|
||||
p.hdel(f'quotas:{self.event_id}:availabilitycache:nocw', str(self.pk))
|
||||
p.hdel(f'quotas:{self.event_id}:availabilitycache:igcl', str(self.pk))
|
||||
p.hdel(f'quotas:{self.event_id}:availabilitycache:nocw:igcl', str(self.pk))
|
||||
p.execute()
|
||||
self.availability(now_dt=now_dt)
|
||||
|
||||
def availability(
|
||||
|
||||
@@ -135,6 +135,7 @@ class QuotaAvailability:
|
||||
|
||||
for eventid, evquotas in quotas_by_event.items():
|
||||
d = rc.hmget(f'quotas:{eventid}:availabilitycache{self._cache_key_suffix}', [str(q.pk) for q in evquotas])
|
||||
print(f'quotas:{eventid}:availabilitycache{self._cache_key_suffix}', [str(q.pk) for q in evquotas], d)
|
||||
for redisval, q in zip(d, evquotas):
|
||||
if redisval is not None:
|
||||
data = [rv for rv in redisval.decode().split(',')]
|
||||
|
||||
@@ -465,6 +465,32 @@ class QuotaTestCase(BaseQuotaTestCase):
|
||||
qa.compute()
|
||||
assert qa.results[self.quota] == (Quota.AVAILABILITY_OK, 1)
|
||||
|
||||
# Rebuild cache required
|
||||
self.quota.size = 5
|
||||
self.quota.save()
|
||||
|
||||
qa = QuotaAvailability(count_waitinglist=True)
|
||||
qa.queue(self.quota)
|
||||
qa.compute(allow_cache=True)
|
||||
assert qa.results[self.quota] == (Quota.AVAILABILITY_ORDERED, 0)
|
||||
|
||||
qa = QuotaAvailability(count_waitinglist=False)
|
||||
qa.queue(self.quota)
|
||||
qa.compute(allow_cache=True)
|
||||
assert qa.results[self.quota] == (Quota.AVAILABILITY_OK, 1)
|
||||
|
||||
self.quota.rebuild_cache()
|
||||
|
||||
qa = QuotaAvailability(count_waitinglist=True)
|
||||
qa.queue(self.quota)
|
||||
qa.compute(allow_cache=True)
|
||||
assert qa.results[self.quota] == (Quota.AVAILABILITY_OK, 4)
|
||||
|
||||
qa = QuotaAvailability(count_waitinglist=False)
|
||||
qa.queue(self.quota)
|
||||
qa.compute(allow_cache=True)
|
||||
assert qa.results[self.quota] == (Quota.AVAILABILITY_OK, 5)
|
||||
|
||||
@classscope(attr='o')
|
||||
def test_waitinglist_variation_fulfilled(self):
|
||||
self.quota.variations.add(self.var1)
|
||||
|
||||
Reference in New Issue
Block a user