Changeset - efb73e7a682f
[Not reviewed]
0 5 0
Christopher Neugebauer - 8 years ago 2016-05-01 04:56:51
chrisjrn@gmail.com
Memoises everything else that needs to be memoised.
5 files changed with 13 insertions and 18 deletions:
0 comments (0 inline, 0 general)
registrasion/controllers/batch.py
Show inline comments
...
 
@@ -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.
 
'''
registrasion/controllers/category.py
Show inline comments
...
 
@@ -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):
 
        '''
 

	
registrasion/controllers/discount.py
Show inline comments
 
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):
 
        '''
 

	
registrasion/controllers/flag.py
Show inline comments
...
 
@@ -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
 

	
registrasion/controllers/product.py
Show inline comments
...
 
@@ -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):
 
        '''
 

	
0 comments (0 inline, 0 general)