# HG changeset patch # User Marcin Kuzminski # Date 2011-11-26 01:01:08 # Node ID 8e9f510912298d4b9e3875cab356815b14278e4a # Parent fe8c2e881403c5b217f480bbb50d2a1b5fcab257 fixed caching query on repos path - small fixes to caching query diff --git a/rhodecode/controllers/home.py b/rhodecode/controllers/home.py --- a/rhodecode/controllers/home.py +++ b/rhodecode/controllers/home.py @@ -45,7 +45,8 @@ class HomeController(BaseController): c.repos_list = self.scm_model.get_repos() - c.groups = RepoGroup.query().filter(RepoGroup.group_parent_id == None).all() + c.groups = RepoGroup.query()\ + .filter(RepoGroup.group_parent_id == None).all() return render('/index.html') diff --git a/rhodecode/lib/caching_query.py b/rhodecode/lib/caching_query.py --- a/rhodecode/lib/caching_query.py +++ b/rhodecode/lib/caching_query.py @@ -137,8 +137,13 @@ def _get_cache_parameters(query): if cache_key is None: # cache key - the value arguments from this query's parameters. - args = _params_from_query(query) - cache_key = " ".join([str(x) for x in args]) + args = [str(x) for x in _params_from_query(query)] + args.extend(filter(lambda k:k not in ['None', None, u'None'], + [str(query._limit), str(query._offset)])) + cache_key = " ".join(args) + + if cache_key is None: + raise Exception('Cache key cannot be None') # get cache #cache = query.cache_manager.get_cache_region(namespace, region) @@ -275,15 +280,20 @@ def _params_from_query(query): """ 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() + if bind.key in query._params: + value = query._params[bind.key] + elif bind.callable: + # lazyloader may dig a callable in here, intended + # to late-evaluate params after autoflush is called. + # convert to a scalar value. + value = bind.callable() + else: + value = bind.value v.append(value) if query._criterion is not None: visitors.traverse(query._criterion, {}, {'bindparam':visit_bindparam}) + for f in query._from_obj: + visitors.traverse(f, {}, {'bindparam':visit_bindparam}) return v diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -573,7 +573,7 @@ class Repository(Base, BaseModel): """ q = Session().query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == Repository.url_sep()) - q.options(FromCache("sql_cache_short", "repository_repo_path")) + q = q.options(FromCache("sql_cache_short", "repository_repo_path")) return q.one().ui_value @property