Bug fixes and query optimisations in flag.py and discount.py
This commit is contained in:
parent
9ca25e5986
commit
b9b50c6846
2 changed files with 5 additions and 1 deletions
|
@ -117,12 +117,14 @@ class DiscountController(object):
|
||||||
|
|
||||||
product_clauses = conditions.DiscountForProduct.objects.all()
|
product_clauses = conditions.DiscountForProduct.objects.all()
|
||||||
product_clauses = product_clauses.select_related(
|
product_clauses = product_clauses.select_related(
|
||||||
|
"discount",
|
||||||
"product",
|
"product",
|
||||||
"product__category",
|
"product__category",
|
||||||
)
|
)
|
||||||
category_clauses = conditions.DiscountForCategory.objects.all()
|
category_clauses = conditions.DiscountForCategory.objects.all()
|
||||||
category_clauses = category_clauses.select_related(
|
category_clauses = category_clauses.select_related(
|
||||||
"category",
|
"category",
|
||||||
|
"discount",
|
||||||
)
|
)
|
||||||
|
|
||||||
valid_discounts = conditions.DiscountBase.objects.all()
|
valid_discounts = conditions.DiscountBase.objects.all()
|
||||||
|
|
|
@ -85,6 +85,8 @@ class FlagController(object):
|
||||||
# from the categories covered by this condition
|
# from the categories covered by this condition
|
||||||
|
|
||||||
ids = [product.id for product in products]
|
ids = [product.id for product in products]
|
||||||
|
|
||||||
|
# TODO: This is re-evaluated a lot.
|
||||||
all_products = inventory.Product.objects.filter(id__in=ids)
|
all_products = inventory.Product.objects.filter(id__in=ids)
|
||||||
cond = (
|
cond = (
|
||||||
Q(flagbase_set=condition) |
|
Q(flagbase_set=condition) |
|
||||||
|
@ -181,7 +183,7 @@ class FlagController(object):
|
||||||
flags = ctrl.pre_filter(flags, user)
|
flags = ctrl.pre_filter(flags, user)
|
||||||
all_subsets.append(flags)
|
all_subsets.append(flags)
|
||||||
|
|
||||||
return itertools.chain(*all_subsets)
|
return list(itertools.chain(*all_subsets))
|
||||||
|
|
||||||
|
|
||||||
ConditionAndRemainder = namedtuple(
|
ConditionAndRemainder = namedtuple(
|
||||||
|
|
Loading…
Reference in a new issue