Re-structure some querying on cart and order pages to reduce load

This commit is contained in:
Raphael Michel
2020-12-13 16:29:17 +01:00
parent 5308099d84
commit 571fef4ed8
7 changed files with 48 additions and 39 deletions

View File

@@ -902,7 +902,7 @@ class Order(LockModel, LoggedModel):
@property
def positions_with_tickets(self):
for op in self.positions.all():
for op in self.positions.select_related('item'):
if not op.generate_ticket:
continue
yield op
@@ -1155,7 +1155,7 @@ class AbstractPosition(models.Model):
(2) questions: a list of Question objects, extended by an 'answer' property
"""
self.answ = {}
for a in self.answers.all():
for a in getattr(self, 'answerlist', self.answers.all()): # use prefetch_related cache from get_cart
self.answ[a.question_id] = a
# We need to clone our question objects, otherwise we will override the cached