Mercurial > kallithea
diff rhodecode/model/caching_query.py @ 784:30d3161c6683 beta
Implemented fancier top menu for logged and anonymous users
little error fix for cached query
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 28 Nov 2010 05:26:26 +0100 |
parents | b0a411f5ec70 |
children | 9e93cad9357b |
line wrap: on
line diff
--- a/rhodecode/model/caching_query.py Sat Nov 27 20:32:34 2010 +0100 +++ b/rhodecode/model/caching_query.py Sun Nov 28 05:26:26 2010 +0100 @@ -55,11 +55,11 @@ the "public" method of configuring this state upon the CachingQuery. """ - + def __init__(self, manager, *args, **kw): self.cache_manager = manager Query.__init__(self, *args, **kw) - + def __iter__(self): """override __iter__ to pull results from Beaker if particular attributes have been configured. @@ -101,7 +101,7 @@ """Set the value in the cache for this query.""" cache, cache_key = _get_cache_parameters(self) - cache.put(cache_key, value) + cache.put(cache_key, value) def query_callable(manager): def query(*arg, **kw): @@ -110,11 +110,11 @@ def get_cache_region(name, region): if region not in beaker.cache.cache_regions: - raise BeakerException('Cache region not configured: %s' + raise BeakerException('Cache region `%s` not configured ' 'Check if proper cache settings are in the .ini files' % region) kw = beaker.cache.cache_regions[region] return beaker.cache.Cache._get_cache(name, kw) - + def _get_cache_parameters(query): """For a query with cache_region and cache_namespace configured, return the correspoinding Cache instance and cache key, based @@ -125,7 +125,7 @@ raise ValueError("This Query does not have caching parameters configured.") region, namespace, cache_key = query._cache_parameters - + namespace = _namespace_from_query(namespace, query) if cache_key is None: @@ -153,15 +153,15 @@ return namespace def _set_cache_parameters(query, region, namespace, cache_key): - + if hasattr(query, '_cache_parameters'): region, namespace, cache_key = query._cache_parameters raise ValueError("This query is already configured " - "for region %r namespace %r" % + "for region %r namespace %r" % (region, namespace) ) query._cache_parameters = region, namespace, cache_key - + class FromCache(MapperOption): """Specifies that a Query should load results from a cache.""" @@ -187,10 +187,10 @@ self.region = region self.namespace = namespace self.cache_key = cache_key - + def process_query(self, query): """Process a Query during normal loading operation.""" - + _set_cache_parameters(query, self.region, self.namespace, self.cache_key) class RelationshipCache(MapperOption): @@ -263,13 +263,13 @@ v = [] def visit_bindparam(bind): value = query._params.get(bind.key, bind.value) - + # lazyloader may dig a callable in here, intended # to late-evaluate params after autoflush is called. # convert to a scalar value. if callable(value): value = value() - + v.append(value) if query._criterion is not None: visitors.traverse(query._criterion, {}, {'bindparam':visit_bindparam})