changeset 612:79457e03ef68

Merge with b0a411f5ec7056bc0b32c8263538b308c33b82f6
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 18 Oct 2010 15:29:56 +0200
parents edf8567be8ed (current diff) b0a411f5ec70 (diff)
children 956952fea94c
files development.ini production.ini rhodecode/config/deployment.ini_tmpl rhodecode/controllers/changelog.py rhodecode/lib/auth.py rhodecode/model/meta.py
diffstat 6 files changed, 34 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/development.ini	Mon Oct 18 15:19:51 2010 +0200
+++ b/development.ini	Mon Oct 18 15:29:56 2010 +0200
@@ -1,6 +1,6 @@
 ################################################################################
 ################################################################################
-# rhodecode - Pylons environment configuration                                    #
+# rhodecode - Pylons environment configuration                                 #
 #                                                                              # 
 # The %(here)s variable will be replaced with the parent directory of this file#
 ################################################################################
@@ -10,7 +10,7 @@
 ################################################################################
 ## Uncomment and replace with the address which should receive                ## 
 ## any error reports after application crash								  ##
-## Additionally those settings will be used by rhodecode mailing system          ##
+## Additionally those settings will be used by rhodecode mailing system       ##
 ################################################################################
 #email_to = admin@localhost
 #error_email_from = paste_error@localhost
@@ -60,6 +60,7 @@
 beaker.cache.long_term.type=memory
 beaker.cache.long_term.expire=36000
 
+
 beaker.cache.sql_cache_short.type=memory
 beaker.cache.sql_cache_short.expire=5
 
--- a/production.ini	Mon Oct 18 15:19:51 2010 +0200
+++ b/production.ini	Mon Oct 18 15:29:56 2010 +0200
@@ -1,6 +1,6 @@
 ################################################################################
 ################################################################################
-# rhodecode - Pylons environment configuration                                    #
+# rhodecode - Pylons environment configuration                                 #
 #                                                                              # 
 # The %(here)s variable will be replaced with the parent directory of this file#
 ################################################################################
@@ -9,8 +9,8 @@
 debug = true
 ################################################################################
 ## Uncomment and replace with the address which should receive                ## 
-## any error reports after application crash								  ##
-## Additionally those settings will be used by rhodecode mailing system          ##
+## any error reports after application crash                                  ##
+## Additionally those settings will be used by rhodecode mailing system       ##
 ################################################################################
 #email_to = admin@localhost
 #error_email_from = paste_error@localhost
@@ -60,6 +60,7 @@
 beaker.cache.long_term.type=memory
 beaker.cache.long_term.expire=36000
 
+
 beaker.cache.sql_cache_short.type=memory
 beaker.cache.sql_cache_short.expire=5
 
@@ -73,7 +74,7 @@
 ###       BEAKER SESSION        ####
 ####################################
 ## Type of storage used for the session, current types are 
-## "dbm", "file", "memcached", "database", and "memory".
+## dbm, file, memcached, database, and memory. 
 ## The storage uses the Container API 
 ##that is also used by the cache system.
 beaker.session.type = file
--- a/rhodecode/config/deployment.ini_tmpl	Mon Oct 18 15:19:51 2010 +0200
+++ b/rhodecode/config/deployment.ini_tmpl	Mon Oct 18 15:29:56 2010 +0200
@@ -74,7 +74,7 @@
 ###       BEAKER SESSION        ####
 ####################################
 ## Type of storage used for the session, current types are 
-## "dbm", "file", "memcached", "database", and "memory".
+## dbm, file, memcached, database, and memory. 
 ## The storage uses the Container API 
 ##that is also used by the cache system.
 beaker.session.type = file
--- a/rhodecode/controllers/changelog.py	Mon Oct 18 15:19:51 2010 +0200
+++ b/rhodecode/controllers/changelog.py	Mon Oct 18 15:29:56 2010 +0200
@@ -23,6 +23,11 @@
 @author: marcink
 """
 
+try:
+    import json
+except ImportError:
+    #python 2.5 compatibility
+    import simplejson as json
 from mercurial.graphmod import colored, CHANGESET, revisions as graph_rev
 from pylons import request, session, tmpl_context as c
 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
@@ -32,12 +37,6 @@
 import logging
 log = logging.getLogger(__name__)
 
-try:
-    import json
-except ImportError:
-    #python 2.5 compatibility
-    import simplejson as json
-
 class ChangelogController(BaseController):
     
     @LoginRequired()
--- a/rhodecode/lib/auth.py	Mon Oct 18 15:19:51 2010 +0200
+++ b/rhodecode/lib/auth.py	Mon Oct 18 15:29:56 2010 +0200
@@ -27,6 +27,7 @@
 from pylons.controllers.util import abort, redirect
 from rhodecode.lib.utils import get_repo_slug
 from rhodecode.model import meta
+from rhodecode.model.caching_query import FromCache
 from rhodecode.model.db import User, RepoToPerm, Repository, Permission, \
     UserToPerm
 from sqlalchemy.exc import OperationalError
@@ -141,7 +142,9 @@
     :param user:
     """
     sa = meta.Session
-    dbuser = sa.query(User).get(user.user_id)
+    dbuser = sa.query(User).options(FromCache('sql_cache_short',
+                                              'getuser_%s' % user.user_id))\
+        .get(user.user_id)
     if dbuser:
         user.username = dbuser.username
         user.is_admin = dbuser.admin
@@ -166,11 +169,14 @@
     #===========================================================================
     # fetch default permissions
     #===========================================================================
+    default_user = sa.query(User)\
+        .options(FromCache('sql_cache_short','getuser_%s' % 'default'))\
+        .filter(User.username == 'default').scalar()
+                                            
     default_perms = sa.query(RepoToPerm, Repository, Permission)\
         .join((Repository, RepoToPerm.repository_id == Repository.repo_id))\
         .join((Permission, RepoToPerm.permission_id == Permission.permission_id))\
-        .filter(RepoToPerm.user == sa.query(User).filter(User.username == 
-                                            'default').scalar()).all()
+        .filter(RepoToPerm.user == default_user).all()
                                             
     if user.is_admin:
         #=======================================================================
--- a/rhodecode/model/caching_query.py	Mon Oct 18 15:19:51 2010 +0200
+++ b/rhodecode/model/caching_query.py	Mon Oct 18 15:29:56 2010 +0200
@@ -18,9 +18,11 @@
 Beaker constructs.
    
 """
+from beaker.exceptions import BeakerException
 from sqlalchemy.orm.interfaces import MapperOption
 from sqlalchemy.orm.query import Query
 from sqlalchemy.sql import visitors
+import beaker
 
 class CachingQuery(Query):
     """A Query subclass which optionally loads full results from a Beaker 
@@ -105,6 +107,13 @@
     def query(*arg, **kw):
         return CachingQuery(manager, *arg, **kw)
     return query
+
+def get_cache_region(name, region):
+    if region not in beaker.cache.cache_regions:
+        raise BeakerException('Cache region not configured: %s'
+            '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,
@@ -125,8 +134,8 @@
         cache_key = " ".join([str(x) for x in args])
 
     # get cache
-    cache = query.cache_manager.get_cache_region(namespace, region)
-
+    #cache = query.cache_manager.get_cache_region(namespace, region)
+    cache = get_cache_region(namespace, region)
     # optional - hash the cache_key too for consistent length
     # import uuid
     # cache_key= str(uuid.uuid5(uuid.NAMESPACE_DNS, cache_key))