From b9b50c68466b7b8d8914de2b476ca28d9e03ff0d Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Sun, 1 May 2016 14:07:29 +1000 Subject: [PATCH] Bug fixes and query optimisations in flag.py and discount.py --- registrasion/controllers/discount.py | 2 ++ registrasion/controllers/flag.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/registrasion/controllers/discount.py b/registrasion/controllers/discount.py index 108ed29b..79785a64 100644 --- a/registrasion/controllers/discount.py +++ b/registrasion/controllers/discount.py @@ -117,12 +117,14 @@ class DiscountController(object): product_clauses = conditions.DiscountForProduct.objects.all() product_clauses = product_clauses.select_related( + "discount", "product", "product__category", ) category_clauses = conditions.DiscountForCategory.objects.all() category_clauses = category_clauses.select_related( "category", + "discount", ) valid_discounts = conditions.DiscountBase.objects.all() diff --git a/registrasion/controllers/flag.py b/registrasion/controllers/flag.py index 879d85f0..29b5be6d 100644 --- a/registrasion/controllers/flag.py +++ b/registrasion/controllers/flag.py @@ -85,6 +85,8 @@ class FlagController(object): # from the categories covered by this condition ids = [product.id for product in products] + + # TODO: This is re-evaluated a lot. all_products = inventory.Product.objects.filter(id__in=ids) cond = ( Q(flagbase_set=condition) | @@ -181,7 +183,7 @@ class FlagController(object): flags = ctrl.pre_filter(flags, user) all_subsets.append(flags) - return itertools.chain(*all_subsets) + return list(itertools.chain(*all_subsets)) ConditionAndRemainder = namedtuple(