diff --git a/registrasion/controllers/batch.py b/registrasion/controllers/batch.py index 3cf95c8a..defd741e 100644 --- a/registrasion/controllers/batch.py +++ b/registrasion/controllers/batch.py @@ -107,16 +107,3 @@ class BatchController(object): cache = {} cache[cls._NESTING_KEY] = 0 return cache - -''' -TODO: memoise CartController.for_user -TODO: memoise user_remainders (Product, Category) -TODO: memoise _filtered_flags -TODO: memoise FlagCounter.count() (doesn't take user, but it'll do for now) -TODO: memoise _filtered_discounts - -Tests: -- ``end_batch`` behaviour for CartController (use for_user *A LOT*) - - discounts not calculated until outermost batch point exits. - - Revision number shouldn't change until outermost batch point exits. -''' diff --git a/registrasion/controllers/category.py b/registrasion/controllers/category.py index 4681f48b..4adf09b6 100644 --- a/registrasion/controllers/category.py +++ b/registrasion/controllers/category.py @@ -7,6 +7,7 @@ from django.db.models import Sum from django.db.models import When from django.db.models import Value +from .batch import BatchController class AllProducts(object): pass @@ -39,6 +40,7 @@ class CategoryController(object): return set(i.category for i in available) @classmethod + @BatchController.memoise def user_remainders(cls, user): ''' diff --git a/registrasion/controllers/discount.py b/registrasion/controllers/discount.py index 29bc1ec6..108ed29b 100644 --- a/registrasion/controllers/discount.py +++ b/registrasion/controllers/discount.py @@ -1,6 +1,8 @@ import itertools -from conditions import ConditionController +from .batch import BatchController +from .conditions import ConditionController + from registrasion.models import commerce from registrasion.models import conditions @@ -10,7 +12,6 @@ from django.db.models import Sum from django.db.models import Value from django.db.models import When - class DiscountAndQuantity(object): ''' Represents a discount that can be applied to a product or category for a given user. @@ -99,6 +100,7 @@ class DiscountController(object): return discounts @classmethod + @BatchController.memoise def _filtered_clauses(cls, user): ''' diff --git a/registrasion/controllers/flag.py b/registrasion/controllers/flag.py index 97456478..879d85f0 100644 --- a/registrasion/controllers/flag.py +++ b/registrasion/controllers/flag.py @@ -6,6 +6,7 @@ from collections import namedtuple from django.db.models import Count from django.db.models import Q +from .batch import BatchController from .conditions import ConditionController from registrasion.models import conditions @@ -115,7 +116,7 @@ class FlagController(object): if not met and product not in messages: messages[product] = message - total_flags = FlagCounter.count() + total_flags = FlagCounter.count(user) valid = {} @@ -158,6 +159,7 @@ class FlagController(object): return error_fields @classmethod + @BatchController.memoise def _filtered_flags(cls, user): ''' @@ -209,11 +211,11 @@ _ConditionsCount = namedtuple( ) -# TODO: this should be cacheable. class FlagCounter(_FlagCounter): @classmethod - def count(cls): + @BatchController.memoise + def count(cls, user): # Get the count of how many conditions should exist per product flagbases = conditions.FlagBase.objects diff --git a/registrasion/controllers/product.py b/registrasion/controllers/product.py index 0810902b..4210bd7c 100644 --- a/registrasion/controllers/product.py +++ b/registrasion/controllers/product.py @@ -9,6 +9,7 @@ from django.db.models import Value from registrasion.models import commerce from registrasion.models import inventory +from .batch import BatchController from .category import CategoryController from .flag import FlagController @@ -55,6 +56,7 @@ class ProductController(object): return out @classmethod + @BatchController.memoise def user_remainders(cls, user): '''