Memoises everything else that needs to be memoised.

This commit is contained in:
Christopher Neugebauer 2016-05-01 12:42:06 +10:00
parent 3d635521eb
commit efb73e7a68
5 changed files with 13 additions and 18 deletions

View file

@ -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.
'''

View file

@ -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):
'''

View file

@ -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):
'''

View file

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

View file

@ -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):
'''