mirror of
https://github.com/pretix/pretix.git
synced 2026-05-09 15:54:03 +00:00
Performance: Cache complete organizer index page, cache subevent list template fragment (#2125)
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
# 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
|
||||
@@ -50,6 +51,7 @@ 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
|
||||
@@ -448,7 +450,8 @@ class EventIndex(EventViewMixin, EventListMixin, CartMixin, TemplateView):
|
||||
context['frontpage_text'] = str(self.request.event.settings.frontpage_text)
|
||||
|
||||
if self.request.event.has_subevents:
|
||||
context.update(self._subevent_list_context())
|
||||
context['subevent_list'] = SimpleLazyObject(self._subevent_list_context)
|
||||
context['subevent_list_cache_key'] = self._subevent_list_cachekey()
|
||||
|
||||
context['show_cart'] = (
|
||||
context['cart']['positions'] and (
|
||||
@@ -465,6 +468,17 @@ 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'):
|
||||
|
||||
Reference in New Issue
Block a user