Bug fixes and query optimisations in flag.py and discount.py

This commit is contained in:
Christopher Neugebauer 2016-05-01 14:07:29 +10:00
parent 9ca25e5986
commit b9b50c6846
2 changed files with 5 additions and 1 deletions

View file

@ -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()

View file

@ -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(