Orders API: Reduce query load imposed by ?pdf_data=true by multiple orders of magnitude

This commit is contained in:
Raphael Michel
2018-09-25 17:39:58 +02:00
parent abd679820f
commit feb262644e
4 changed files with 45 additions and 9 deletions

View File

@@ -36,10 +36,15 @@ def register_data(sender, **kwargs):
def get_answer(op, order, event, question_id):
try:
a = op.answers.get(question_id=question_id)
if 'answers' in op._prefetched_objects_cache:
a = [a for a in op.answers.all() if a.question_id == question_id][0]
else:
a = op.answers.get(question_id=question_id)
return str(a).replace("\n", "<br/>\n")
except QuestionAnswer.DoesNotExist:
return ""
except IndexError:
return ""
@receiver(layout_text_variables, dispatch_uid="pretix_ticketoutputpdf_layout_text_variables_questions")