From 245ad644ff0cc16f2a881c0e9fa67417b877e8ae Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Thu, 11 Nov 2021 10:02:45 +0100 Subject: [PATCH] Subevent calendar: Improve heuristic on when to show names (#2308) --- src/pretix/presale/views/event.py | 22 ++++++++++++++++------ src/pretix/presale/views/organizer.py | 5 ----- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/pretix/presale/views/event.py b/src/pretix/presale/views/event.py index 7dcc4c540d..87f6400afe 100644 --- a/src/pretix/presale/views/event.py +++ b/src/pretix/presale/views/event.py @@ -569,9 +569,14 @@ class EventIndex(EventViewMixin, EventListMixin, CartMixin, TemplateView): voucher, ) - context['show_names'] = ebd.get('_subevents_different_names', False) or sum( - len(i) for i in ebd.values() if isinstance(i, list) - ) < 2 + # Hide names of subevents in event series where it is always the same. No need to show the name of the museum thousands of times + # in the calendar. We previously only looked at the current time range for this condition which caused weird side-effects, so we need + # an extra query to look at the entire series. For performance reasons, we have a limit on how many different names we look at. + context['show_names'] = sum(len(i) for i in ebd.values() if isinstance(i, list)) < 2 or self.request.event.cache.get_or_set( + 'has_different_subevent_names', + lambda: len(set(str(n) for n in self.request.event.subevents.values_list('name', flat=True).annotate(c=Count('*'))[:250])) != 1, + timeout=120, + ) context['weeks'] = weeks_for_template(ebd, self.year, self.month) context['months'] = [date(self.year, i + 1, 1) for i in range(12)] context['years'] = range(now().year - 2, now().year + 3) @@ -598,9 +603,14 @@ class EventIndex(EventViewMixin, EventListMixin, CartMixin, TemplateView): voucher, ) - context['show_names'] = ebd.get('_subevents_different_names', False) or sum( - len(i) for i in ebd.values() if isinstance(i, list) - ) < 2 + # Hide names of subevents in event series where it is always the same. No need to show the name of the museum thousands of times + # in the calendar. We previously only looked at the current time range for this condition which caused weird side-effects, so we need + # an extra query to look at the entire series. For performance reasons, we have a limit on how many different names we look at. + context['show_names'] = sum(len(i) for i in ebd.values() if isinstance(i, list)) < 2 or self.request.event.cache.get_or_set( + 'has_different_subevent_names', + lambda: len(set(str(n) for n in self.request.event.subevents.values_list('name', flat=True).annotate(c=Count('*'))[:250])) != 1, + timeout=120, + ) context['days'] = days_for_template(ebd, week) context['weeks'] = [ (date_fromisocalendar(self.year, i + 1, 1), date_fromisocalendar(self.year, i + 1, 7)) diff --git a/src/pretix/presale/views/organizer.py b/src/pretix/presale/views/organizer.py index 99be5d9b1a..8c057bc5cf 100644 --- a/src/pretix/presale/views/organizer.py +++ b/src/pretix/presale/views/organizer.py @@ -470,7 +470,6 @@ def add_subevents_for_days(qs, before, after, ebd, timezones, event=None, cart_n if se.presale_is_running: quotas_to_compute += se.active_quotas - name = None qcache = {} if quotas_to_compute: qa = QuotaAvailability() @@ -500,10 +499,6 @@ def add_subevents_for_days(qs, before, after, ebd, timezones, event=None, cart_n tz = pytz.timezone(s.timezone) datetime_from = se.date_from.astimezone(tz) date_from = datetime_from.date() - if name is None: - name = str(se.name) - elif str(se.name) != name: - ebd['_subevents_different_names'] = True if s.show_date_to and se.date_to: datetime_to = se.date_to.astimezone(tz) date_to = se.date_to.astimezone(tz).date()