Mercurial > kallithea
changeset 2062:bf8ed0adbc66 beta
fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 28 Feb 2012 18:25:30 +0200 |
parents | 9f0fe6777833 |
children | d9ba58526712 |
files | docs/changelog.rst rhodecode/lib/caching_query.py rhodecode/model/db.py |
diffstat | 3 files changed, 24 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/docs/changelog.rst Tue Feb 28 17:44:17 2012 +0200 +++ b/docs/changelog.rst Tue Feb 28 18:25:30 2012 +0200 @@ -23,6 +23,8 @@ - fixes #368 improved git-protocol detection to handle other clients - fixes #366 When Setting Repository Group To Blank Repo Group Wont Be Moved To Root +- fixes #371 fixed issues with beaker/sqlalchemy and non-ascii cache keys + 1.3.1 (**2012-02-27**) ----------------------
--- a/rhodecode/lib/caching_query.py Tue Feb 28 17:44:17 2012 +0200 +++ b/rhodecode/lib/caching_query.py Tue Feb 28 18:25:30 2012 +0200 @@ -24,6 +24,7 @@ from sqlalchemy.orm.interfaces import MapperOption from sqlalchemy.orm.query import Query from sqlalchemy.sql import visitors +from rhodecode.lib import safe_str class CachingQuery(Query): @@ -137,9 +138,10 @@ if cache_key is None: # cache key - the value arguments from this query's parameters. - args = [str(x) for x in _params_from_query(query)] - args.extend(filter(lambda k:k not in ['None', None, u'None'], + args = [safe_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:
--- a/rhodecode/model/db.py Tue Feb 28 17:44:17 2012 +0200 +++ b/rhodecode/model/db.py Tue Feb 28 18:25:30 2012 +0200 @@ -44,6 +44,7 @@ from rhodecode.lib.caching_query import FromCache from rhodecode.model.meta import Base, Session +import hashlib log = logging.getLogger(__name__) @@ -52,6 +53,8 @@ # BASE CLASSES #============================================================================== +_hash_key = lambda k: hashlib.md5(safe_str(k)).hexdigest() + class ModelSerializer(json.JSONEncoder): """ @@ -337,8 +340,11 @@ q = cls.query().filter(cls.username == username) if cache: - q = q.options(FromCache("sql_cache_short", - "get_user_%s" % username)) + q = q.options(FromCache( + "sql_cache_short", + "get_user_%s" % _hash_key(username) + ) + ) return q.scalar() @classmethod @@ -418,8 +424,11 @@ else: q = cls.query().filter(cls.users_group_name == group_name) if cache: - q = q.options(FromCache("sql_cache_short", - "get_user_%s" % group_name)) + q = q.options(FromCache( + "sql_cache_short", + "get_user_%s" % _hash_key(group_name) + ) + ) return q.scalar() @classmethod @@ -748,8 +757,11 @@ gr = cls.query()\ .filter(cls.group_name == group_name) if cache: - gr = gr.options(FromCache("sql_cache_short", - "get_group_%s" % group_name)) + gr = gr.options(FromCache( + "sql_cache_short", + "get_group_%s" % _hash_key(group_name) + ) + ) return gr.scalar() @property