Revert "Performance: Cache complete organizer index page, cache subevent list template fragment (#2125)"

This reverts commit ba895270fa.
This commit is contained in:
Raphael Michel
2021-06-14 23:16:19 +02:00
parent eb77f67d28
commit 5801c8602e
6 changed files with 31 additions and 108 deletions

View File

@@ -9,21 +9,21 @@
{% endfor %} {% endfor %}
<div class="row"> <div class="row">
<div class="col-sm-4 hidden-xs text-left flip"> <div class="col-sm-4 hidden-xs text-left flip">
<a href="?{% url_replace request "year" subevent_list.before.year "month" subevent_list.before.month %}" <a href="?{% url_replace request "year" before.year "month" before.month %}"
class="btn btn-default"> class="btn btn-default">
<span class="fa fa-arrow-left" aria-hidden="true"></span> <span class="fa fa-arrow-left" aria-hidden="true"></span>
{{ subevent_list.before|date:"F Y" }} {{ before|date:"F Y" }}
</a> </a>
</div> </div>
<div class="col-sm-4 col-xs-12 text-center"> <div class="col-sm-4 col-xs-12 text-center">
<select name="month" class="form-control"> <select name="month" class="form-control">
{% for m in subevent_list.months %} {% for m in months %}
<option value="{{ m|date:"m" }}" {% if m == subevent_list.date.month %}selected{% endif %}>{{ m|date:"F" }}</option> <option value="{{ m|date:"m" }}" {% if m == date %}selected{% endif %}>{{ m|date:"F" }}</option>
{% endfor %} {% endfor %}
</select> </select>
<select name="year" class="form-control"> <select name="year" class="form-control">
{% for y in subevent_list.years %} {% for y in years %}
<option value="{{ y }}" {% if y == subevent_list.date.year %}selected{% endif %}>{{ y }}</option> <option value="{{ y }}" {% if y == date.year %}selected{% endif %}>{{ y }}</option>
{% endfor %} {% endfor %}
</select> </select>
<button type="submit" class="js-hidden btn btn-default"> <button type="submit" class="js-hidden btn btn-default">
@@ -31,11 +31,11 @@
</button> </button>
</div> </div>
<div class="col-sm-4 hidden-xs text-right flip"> <div class="col-sm-4 hidden-xs text-right flip">
<a href="?{% url_replace request "year" subevent_list.after.year "month" subevent_list.after.month %}" class="btn btn-default"> <a href="?{% url_replace request "year" after.year "month" after.month %}" class="btn btn-default">
{{ subevent_list.after|date:"F Y" }} {{ after|date:"F Y" }}
<span class="fa fa-arrow-right" aria-hidden="true"></span> <span class="fa fa-arrow-right" aria-hidden="true"></span>
</a> </a>
</div> </div>
</div> </div>
</form> </form>
{% include "pretixpresale/fragment_calendar.html" with show_avail=event.settings.event_list_availability weeks=subevent_list.weeks %} {% include "pretixpresale/fragment_calendar.html" with show_avail=event.settings.event_list_availability %}

View File

@@ -9,21 +9,21 @@
{% endfor %} {% endfor %}
<div class="row"> <div class="row">
<div class="col-sm-4 hidden-xs text-left flip"> <div class="col-sm-4 hidden-xs text-left flip">
<a href="?{% url_replace request "year" subevent_list.before.isocalendar.0 "week" subevent_list.before.isocalendar.1 %}" <a href="?{% url_replace request "year" before.isocalendar.0 "week" before.isocalendar.1 %}"
class="btn btn-default"> class="btn btn-default">
<span class="fa fa-arrow-left" aria-hidden="true"></span> <span class="fa fa-arrow-left" aria-hidden="true"></span>
{{ before|date:subevent_list.week_format }} {{ before|date:week_format }}
</a> </a>
</div> </div>
<div class="col-sm-4 col-xs-12 text-center"> <div class="col-sm-4 col-xs-12 text-center">
<select name="week" class="form-control select-calendar-week-short"> <select name="week" class="form-control select-calendar-week-short">
{% for w in subevent_list.weeks %} {% for w in weeks %}
<option value="{{ w.0.isocalendar.1 }}" {% if w.0.isocalendar.1 == subevent_list.date.isocalendar.1 %}selected{% endif %}>{% trans "W" %} {{ w.0.isocalendar.1 }} ({{ w.0|date:"SHORT_DATE_FORMAT" }} {{ w.1|date:"SHORT_DATE_FORMAT" }})</option> <option value="{{ w.0.isocalendar.1 }}" {% if w.0.isocalendar.1 == date.isocalendar.1 %}selected{% endif %}>{% trans "W" %} {{ w.0.isocalendar.1 }} ({{ w.0|date:"SHORT_DATE_FORMAT" }} {{ w.1|date:"SHORT_DATE_FORMAT" }})</option>
{% endfor %} {% endfor %}
</select> </select>
<select name="year" class="form-control"> <select name="year" class="form-control">
{% for y in subevent_list.years %} {% for y in years %}
<option value="{{ y }}" {% if y == subevent_list.date.isocalendar.0 %}selected{% endif %}>{{ y }}</option> <option value="{{ y }}" {% if y == date.isocalendar.0 %}selected{% endif %}>{{ y }}</option>
{% endfor %} {% endfor %}
</select> </select>
<button type="submit" class="js-hidden btn btn-default"> <button type="submit" class="js-hidden btn btn-default">
@@ -31,24 +31,24 @@
</button> </button>
</div> </div>
<div class="col-sm-4 hidden-xs text-right flip"> <div class="col-sm-4 hidden-xs text-right flip">
<a href="?{% url_replace request "year" subevent_list.after.isocalendar.0 "week" subevent_list.after.isocalendar.1 %}" <a href="?{% url_replace request "year" after.isocalendar.0 "week" after.isocalendar.1 %}"
class="btn btn-default"> class="btn btn-default">
{{ subevent_list.after|date:subevent_list.week_format }} {{ after|date:week_format }}
<span class="fa fa-arrow-right" aria-hidden="true"></span> <span class="fa fa-arrow-right" aria-hidden="true"></span>
</a> </a>
</div> </div>
</div> </div>
</form> </form>
{% include "pretixpresale/fragment_week_calendar.html" with show_avail=event.settings.event_list_availability days=subevent_list.days %} {% include "pretixpresale/fragment_week_calendar.html" with show_avail=event.settings.event_list_availability %}
<div class="col-sm-4 visible-xs text-center"> <div class="col-sm-4 visible-xs text-center">
<a href="?{% url_replace request "year" subevent_list.before.isocalendar.0 "week" subevent_list.before.isocalendar.1 %}" <a href="?{% url_replace request "year" before.isocalendar.0 "week" before.isocalendar.1 %}"
class="btn btn-default"> class="btn btn-default">
<span class="fa fa-arrow-left" aria-hidden="true"></span> <span class="fa fa-arrow-left" aria-hidden="true"></span>
{{ subevent_list.before|date:subevent_list.week_format }} {{ before|date:week_format }}
</a> </a>
<a href="?{% url_replace request "year" subevent_list.after.isocalendar.0 "week" subevent_list.after.isocalendar.1 %}" <a href="?{% url_replace request "year" after.isocalendar.0 "week" after.isocalendar.1 %}"
class="btn btn-default"> class="btn btn-default">
{{ subevent_list.after|date:subevent_list.week_format }} {{ after|date:week_format }}
<span class="fa fa-arrow-right" aria-hidden="true"></span> <span class="fa fa-arrow-right" aria-hidden="true"></span>
</a> </a>
</div> </div>

View File

@@ -1,6 +1,6 @@
{% load i18n %} {% load i18n %}
{% load eventurl %} {% load eventurl %}
{% for subev in subevent_list.subevent_list %} {% for subev in subevent_list %}
<a href="{% if request.GET.voucher %}{% eventurl event "presale:event.redeem" cart_namespace=cart_namespace %}?voucher={{ request.GET.voucher|urlencode }}&subevent={{ subev.pk }}{% else %}{% eventurl event "presale:event.index" subevent=subev.id cart_namespace=cart_namespace %}{% endif %}" <a href="{% if request.GET.voucher %}{% eventurl event "presale:event.redeem" cart_namespace=cart_namespace %}?voucher={{ request.GET.voucher|urlencode }}&subevent={{ subev.pk }}{% else %}{% eventurl event "presale:event.index" subevent=subev.id cart_namespace=cart_namespace %}{% endif %}"
class="subevent-row"> class="subevent-row">
<div class="row"> <div class="row">

View File

@@ -2,7 +2,6 @@
{% load i18n %} {% load i18n %}
{% load l10n %} {% load l10n %}
{% load eventurl %} {% load eventurl %}
{% load cache %}
{% load money %} {% load money %}
{% load thumb %} {% load thumb %}
{% load eventsignal %} {% load eventsignal %}
@@ -74,15 +73,13 @@
</div> </div>
<div class="panel-body"> <div class="panel-body">
<div> <div>
{% cache 15 subevent_lits subevent_list_cache_key %} {% if list_type == "calendar" %}
{% if subevent_list.list_type == "calendar" %} {% include "pretixpresale/event/fragment_subevent_calendar.html" %}
{% include "pretixpresale/event/fragment_subevent_calendar.html" %} {% elif list_type == "week" %}
{% elif subevent_list.list_type == "week" %} {% include "pretixpresale/event/fragment_subevent_calendar_week.html" %}
{% include "pretixpresale/event/fragment_subevent_calendar_week.html" %} {% else %}
{% else %} {% include "pretixpresale/event/fragment_subevent_list.html" %}
{% include "pretixpresale/event/fragment_subevent_list.html" %} {% endif %}
{% endif %}
{% endcache %}
</div> </div>
</div> </div>
</div> </div>

View File

@@ -33,7 +33,6 @@
# License for the specific language governing permissions and limitations under the License. # License for the specific language governing permissions and limitations under the License.
import calendar import calendar
import hashlib
import sys import sys
from collections import defaultdict from collections import defaultdict
from datetime import date, datetime, timedelta 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.shortcuts import get_object_or_404, redirect, render
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.utils.formats import get_format from django.utils.formats import get_format
from django.utils.functional import SimpleLazyObject
from django.utils.timezone import now from django.utils.timezone import now
from django.utils.translation import gettext_lazy as _, pgettext_lazy from django.utils.translation import gettext_lazy as _, pgettext_lazy
from django.views import View 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) context['frontpage_text'] = str(self.request.event.settings.frontpage_text)
if self.request.event.has_subevents: if self.request.event.has_subevents:
context['subevent_list'] = SimpleLazyObject(self._subevent_list_context) context.update(self._subevent_list_context())
context['subevent_list_cache_key'] = self._subevent_list_cachekey()
context['show_cart'] = ( context['show_cart'] = (
context['cart']['positions'] and ( context['cart']['positions'] and (
@@ -468,17 +465,6 @@ class EventIndex(EventViewMixin, EventListMixin, CartMixin, TemplateView):
return context 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): def _subevent_list_context(self):
voucher = None voucher = None
if self.request.GET.get('voucher'): if self.request.GET.get('voucher'):

View File

@@ -33,7 +33,6 @@
# License for the specific language governing permissions and limitations under the License. # License for the specific language governing permissions and limitations under the License.
import calendar import calendar
import hashlib
from collections import defaultdict from collections import defaultdict
from datetime import date, datetime, time, timedelta from datetime import date, datetime, time, timedelta
from urllib.parse import quote from urllib.parse import quote
@@ -41,7 +40,6 @@ from urllib.parse import quote
import isoweek import isoweek
import pytz import pytz
from django.conf import settings 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 import Exists, Max, Min, OuterRef, Q
from django.db.models.functions import Coalesce, Greatest from django.db.models.functions import Coalesce, Greatest
from django.http import Http404, HttpResponse from django.http import Http404, HttpResponse
@@ -308,64 +306,6 @@ class OrganizerIndex(OrganizerViewMixin, EventListMixin, ListView):
template_name = 'pretixpresale/organizers/index.html' template_name = 'pretixpresale/organizers/index.html'
paginate_by = 30 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): def get(self, request, *args, **kwargs):
style = request.GET.get("style", request.organizer.settings.event_list_type) style = request.GET.get("style", request.organizer.settings.event_list_type)
if style == "calendar": if style == "calendar":