forked from CGM_Public/pretix_original
Revert "Performance: Cache complete organizer index page, cache subevent list template fragment (#2125)"
This reverts commit ba895270fa.
This commit is contained in:
@@ -33,7 +33,6 @@
|
||||
# License for the specific language governing permissions and limitations under the License.
|
||||
|
||||
import calendar
|
||||
import hashlib
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
from datetime import date, datetime, timedelta
|
||||
@@ -51,7 +50,6 @@ from django.http import Http404, HttpResponse
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.utils.formats import get_format
|
||||
from django.utils.functional import SimpleLazyObject
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import gettext_lazy as _, pgettext_lazy
|
||||
from django.views import View
|
||||
@@ -450,8 +448,7 @@ class EventIndex(EventViewMixin, EventListMixin, CartMixin, TemplateView):
|
||||
context['frontpage_text'] = str(self.request.event.settings.frontpage_text)
|
||||
|
||||
if self.request.event.has_subevents:
|
||||
context['subevent_list'] = SimpleLazyObject(self._subevent_list_context)
|
||||
context['subevent_list_cache_key'] = self._subevent_list_cachekey()
|
||||
context.update(self._subevent_list_context())
|
||||
|
||||
context['show_cart'] = (
|
||||
context['cart']['positions'] and (
|
||||
@@ -468,17 +465,6 @@ class EventIndex(EventViewMixin, EventListMixin, CartMixin, TemplateView):
|
||||
|
||||
return context
|
||||
|
||||
def _subevent_list_cachekey(self):
|
||||
cache_key_parts = [
|
||||
self.request.host,
|
||||
str(self.request.event.pk),
|
||||
self.request.get_full_path(),
|
||||
self.request.LANGUAGE_CODE,
|
||||
self.request.sales_channel.identifier,
|
||||
]
|
||||
cache_key = f'pretix.presale.views.event.EventIndex.subevent_list_context:{hashlib.md5(":".join(cache_key_parts).encode()).hexdigest()}'
|
||||
return cache_key
|
||||
|
||||
def _subevent_list_context(self):
|
||||
voucher = None
|
||||
if self.request.GET.get('voucher'):
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
# License for the specific language governing permissions and limitations under the License.
|
||||
|
||||
import calendar
|
||||
import hashlib
|
||||
from collections import defaultdict
|
||||
from datetime import date, datetime, time, timedelta
|
||||
from urllib.parse import quote
|
||||
@@ -41,7 +40,6 @@ from urllib.parse import quote
|
||||
import isoweek
|
||||
import pytz
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.db.models import Exists, Max, Min, OuterRef, Q
|
||||
from django.db.models.functions import Coalesce, Greatest
|
||||
from django.http import Http404, HttpResponse
|
||||
@@ -308,64 +306,6 @@ class OrganizerIndex(OrganizerViewMixin, EventListMixin, ListView):
|
||||
template_name = 'pretixpresale/organizers/index.html'
|
||||
paginate_by = 30
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
# In stock pretix, nothing on this page is session-dependent except for the language and the customer login part,
|
||||
# so we can cache pretty aggressively if the user is anonymous. Note that we deliberately implement the caching
|
||||
# on the view layer, *after* all middlewares have been ran, so we have access to the computed locale, as well
|
||||
# as the login status etc.
|
||||
cache_allowed = (
|
||||
not getattr(request, 'customer', None) and not request.user.is_authenticated
|
||||
)
|
||||
cache_key_parts = [
|
||||
request.method,
|
||||
request.host,
|
||||
str(request.organizer.pk),
|
||||
request.get_full_path(),
|
||||
request.LANGUAGE_CODE,
|
||||
self.request.sales_channel.identifier,
|
||||
]
|
||||
for c, v in request.COOKIES.items():
|
||||
# If the cookie is not one we know, it might be set by a plugin and we need to include it in the
|
||||
# cache key to be safe. A known example includes plugins that e.g. store cookie banner state.
|
||||
if c not in (settings.SESSION_COOKIE_NAME, settings.LANGUAGE_COOKIE_NAME, settings.CSRF_COOKIE_NAME):
|
||||
cache_key_parts.append(f'{c}={v}')
|
||||
for c, v in request.session.items():
|
||||
# If the session key is not one we know, it might be set by a plugin and we need to include it in the
|
||||
# cache key to be safe. A known example would be the pretix-campaigns plugin setting the campaign ID.
|
||||
if (
|
||||
not c.startswith('_auth') and
|
||||
not c.startswith('pretix_auth_') and
|
||||
not c.startswith('customer_auth_') and
|
||||
not c.startswith('current_cart_') and
|
||||
not c.startswith('cart_') and
|
||||
not c.startswith('payment_') and
|
||||
c not in ('carts', 'payment', 'pinned_user_agent')
|
||||
):
|
||||
cache_key_parts.append(f'{c}={repr(v)}')
|
||||
|
||||
cache_key = f'pretix.presale.views.organizer.OrganizerIndex:{hashlib.md5(":".join(cache_key_parts).encode()).hexdigest()}'
|
||||
cache_timeout = 15
|
||||
|
||||
if not cache_allowed:
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
response = cache.get(cache_key)
|
||||
if response is not None:
|
||||
return response
|
||||
|
||||
response = super().dispatch(request, *kwargs, **kwargs)
|
||||
if response.status_code >= 400:
|
||||
return response
|
||||
|
||||
if hasattr(response, 'render') and callable(response.render):
|
||||
def _store_to_cache(r):
|
||||
cache.set(cache_key, r, cache_timeout)
|
||||
|
||||
response.add_post_render_callback(_store_to_cache)
|
||||
else:
|
||||
cache.set(cache_key, response, cache_timeout)
|
||||
return response
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
style = request.GET.get("style", request.organizer.settings.event_list_type)
|
||||
if style == "calendar":
|
||||
|
||||
Reference in New Issue
Block a user