Add cache_model() method to app handler
				
					
				
			also make cache_model() always return an OrderedDict, in case the ordering actually matters to caller
This commit is contained in:
		
							parent
							
								
									785f98547e
								
							
						
					
					
						commit
						601596d8bf
					
				
					 2 changed files with 13 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -135,6 +135,15 @@ class AppHandler(object):
 | 
			
		|||
        from rattail.db import Session
 | 
			
		||||
        return Session(**kwargs)
 | 
			
		||||
 | 
			
		||||
    def cache_model(self, session, model, **kwargs):
 | 
			
		||||
        """
 | 
			
		||||
        Convenience method which invokes
 | 
			
		||||
        :func:`rattail.db.cache.cache_model()` with the given model
 | 
			
		||||
        and keyword arguments.
 | 
			
		||||
        """
 | 
			
		||||
        from rattail.db import cache
 | 
			
		||||
        return cache.cache_model(session, model, **kwargs)
 | 
			
		||||
 | 
			
		||||
    def make_temp_dir(self, **kwargs):
 | 
			
		||||
        """
 | 
			
		||||
        Create a temporary directory.  This is mostly a convenience wrapper
 | 
			
		||||
| 
						 | 
				
			
			@ -258,8 +267,7 @@ class GenericHandler(object):
 | 
			
		|||
        Convenience method which invokes :func:`rattail.db.cache.cache_model()`
 | 
			
		||||
        with the given model and keyword arguments.
 | 
			
		||||
        """
 | 
			
		||||
        from rattail.db import cache
 | 
			
		||||
        return cache.cache_model(session, model, **kwargs)
 | 
			
		||||
        return self.app.cache_model(session, model, **kwargs)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def make_app(config, **kwargs):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,7 @@
 | 
			
		|||
################################################################################
 | 
			
		||||
#
 | 
			
		||||
#  Rattail -- Retail Software Framework
 | 
			
		||||
#  Copyright © 2010-2018 Lance Edgar
 | 
			
		||||
#  Copyright © 2010-2021 Lance Edgar
 | 
			
		||||
#
 | 
			
		||||
#  This file is part of Rattail.
 | 
			
		||||
#
 | 
			
		||||
| 
						 | 
				
			
			@ -33,6 +33,7 @@ from sqlalchemy.orm import joinedload
 | 
			
		|||
 | 
			
		||||
from rattail.core import Object
 | 
			
		||||
from rattail.db import model
 | 
			
		||||
from rattail.util import OrderedDict
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
log = logging.getLogger(__name__)
 | 
			
		||||
| 
						 | 
				
			
			@ -88,7 +89,7 @@ class ModelCacher(object):
 | 
			
		|||
        return q
 | 
			
		||||
 | 
			
		||||
    def get_cache(self, progress):
 | 
			
		||||
        self.instances = {}
 | 
			
		||||
        self.instances = OrderedDict()
 | 
			
		||||
        query = self.query()
 | 
			
		||||
        count = query.count()
 | 
			
		||||
        if not count:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue