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
|
@ -135,6 +135,15 @@ class AppHandler(object):
|
||||||
from rattail.db import Session
|
from rattail.db import Session
|
||||||
return Session(**kwargs)
|
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):
|
def make_temp_dir(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
Create a temporary directory. This is mostly a convenience wrapper
|
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()`
|
Convenience method which invokes :func:`rattail.db.cache.cache_model()`
|
||||||
with the given model and keyword arguments.
|
with the given model and keyword arguments.
|
||||||
"""
|
"""
|
||||||
from rattail.db import cache
|
return self.app.cache_model(session, model, **kwargs)
|
||||||
return cache.cache_model(session, model, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
def make_app(config, **kwargs):
|
def make_app(config, **kwargs):
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2018 Lance Edgar
|
# Copyright © 2010-2021 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -33,6 +33,7 @@ from sqlalchemy.orm import joinedload
|
||||||
|
|
||||||
from rattail.core import Object
|
from rattail.core import Object
|
||||||
from rattail.db import model
|
from rattail.db import model
|
||||||
|
from rattail.util import OrderedDict
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -88,7 +89,7 @@ class ModelCacher(object):
|
||||||
return q
|
return q
|
||||||
|
|
||||||
def get_cache(self, progress):
|
def get_cache(self, progress):
|
||||||
self.instances = {}
|
self.instances = OrderedDict()
|
||||||
query = self.query()
|
query = self.query()
|
||||||
count = query.count()
|
count = query.count()
|
||||||
if not count:
|
if not count:
|
||||||
|
|
Loading…
Reference in a new issue