From 5024fae5ed475c4a83da19bc589ca1293edbfd00 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Tue, 12 Mar 2019 09:53:28 +0100 Subject: [PATCH] Improve performance of bulk-generation of ticket PDFs --- .../plugins/ticketoutputpdf/ticketoutput.py | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/pretix/plugins/ticketoutputpdf/ticketoutput.py b/src/pretix/plugins/ticketoutputpdf/ticketoutput.py index b64321e6f5..c72d0cd20a 100644 --- a/src/pretix/plugins/ticketoutputpdf/ticketoutput.py +++ b/src/pretix/plugins/ticketoutputpdf/ticketoutput.py @@ -35,19 +35,23 @@ class PdfTicketOutput(BaseTicketOutput): @cached_property def layout_map(self): - return { - (bi.item_id, bi.sales_channel): bi.layout - for bi in TicketLayoutItem.objects.select_related('layout').filter(item__event=self.event) - } + if not hasattr(self.event, '_ticketoutputpdf_cache_layoutmap'): + self.event._ticketoutputpdf_cache_layoutmap = { + (bi.item_id, bi.sales_channel): bi.layout + for bi in TicketLayoutItem.objects.select_related('layout').filter(item__event=self.event) + } + return self.event._ticketoutputpdf_cache_layoutmap @cached_property def default_layout(self): - try: - return self.event.ticket_layouts.get(default=True) - except TicketLayout.DoesNotExist: - return TicketLayout( - layout=json.dumps(self._default_layout()) - ) + if not hasattr(self.event, '_ticketoutputpdf_cache_default_layout'): + try: + self.event._ticketoutputpdf_cache_default_layout = self.event.ticket_layouts.get(default=True) + except TicketLayout.DoesNotExist: + self.event._ticketoutputpdf_cache_default_layout = TicketLayout( + layout=json.dumps(self._default_layout()) + ) + return self.event._ticketoutputpdf_cache_default_layout def _register_fonts(self): Renderer._register_fonts()