changeset 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 fe8c2e881403
children 07e56179633e
files rhodecode/controllers/home.py rhodecode/lib/caching_query.py rhodecode/model/db.py
diffstat 3 files changed, 21 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/controllers/home.py	Sat Nov 26 02:23:28 2011 +0200
+++ b/rhodecode/controllers/home.py	Sat Nov 26 03:01:08 2011 +0200
@@ -45,7 +45,8 @@
 
         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')
 
--- a/rhodecode/lib/caching_query.py	Sat Nov 26 02:23:28 2011 +0200
+++ b/rhodecode/lib/caching_query.py	Sat Nov 26 03:01:08 2011 +0200
@@ -137,8 +137,13 @@
 
     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 @@
     """
     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
--- a/rhodecode/model/db.py	Sat Nov 26 02:23:28 2011 +0200
+++ b/rhodecode/model/db.py	Sat Nov 26 03:01:08 2011 +0200
@@ -573,7 +573,7 @@
         """
         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