Mercurial > kallithea
comparison rhodecode/lib/caching_query.py @ 1727:8e9f51091229 beta
fixed caching query on repos path
- small fixes to caching query
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 26 Nov 2011 03:01:08 +0200 |
parents | f522f4d3bf93 |
children | bf8ed0adbc66 |
comparison
equal
deleted
inserted
replaced
1726:fe8c2e881403 | 1727:8e9f51091229 |
---|---|
135 | 135 |
136 namespace = _namespace_from_query(namespace, query) | 136 namespace = _namespace_from_query(namespace, query) |
137 | 137 |
138 if cache_key is None: | 138 if cache_key is None: |
139 # cache key - the value arguments from this query's parameters. | 139 # cache key - the value arguments from this query's parameters. |
140 args = _params_from_query(query) | 140 args = [str(x) for x in _params_from_query(query)] |
141 cache_key = " ".join([str(x) for x in args]) | 141 args.extend(filter(lambda k:k not in ['None', None, u'None'], |
142 [str(query._limit), str(query._offset)])) | |
143 cache_key = " ".join(args) | |
144 | |
145 if cache_key is None: | |
146 raise Exception('Cache key cannot be None') | |
142 | 147 |
143 # get cache | 148 # get cache |
144 #cache = query.cache_manager.get_cache_region(namespace, region) | 149 #cache = query.cache_manager.get_cache_region(namespace, region) |
145 cache = get_cache_region(namespace, region) | 150 cache = get_cache_region(namespace, region) |
146 # optional - hash the cache_key too for consistent length | 151 # optional - hash the cache_key too for consistent length |
273 would return [5, 7]. | 278 would return [5, 7]. |
274 | 279 |
275 """ | 280 """ |
276 v = [] | 281 v = [] |
277 def visit_bindparam(bind): | 282 def visit_bindparam(bind): |
278 value = query._params.get(bind.key, bind.value) | 283 |
279 | 284 if bind.key in query._params: |
280 # lazyloader may dig a callable in here, intended | 285 value = query._params[bind.key] |
281 # to late-evaluate params after autoflush is called. | 286 elif bind.callable: |
282 # convert to a scalar value. | 287 # lazyloader may dig a callable in here, intended |
283 if callable(value): | 288 # to late-evaluate params after autoflush is called. |
284 value = value() | 289 # convert to a scalar value. |
290 value = bind.callable() | |
291 else: | |
292 value = bind.value | |
285 | 293 |
286 v.append(value) | 294 v.append(value) |
287 if query._criterion is not None: | 295 if query._criterion is not None: |
288 visitors.traverse(query._criterion, {}, {'bindparam':visit_bindparam}) | 296 visitors.traverse(query._criterion, {}, {'bindparam':visit_bindparam}) |
297 for f in query._from_obj: | |
298 visitors.traverse(f, {}, {'bindparam':visit_bindparam}) | |
289 return v | 299 return v |