diff pylons_app/lib/utils.py @ 343:6484963056cd

implemented cache for repeated queries in simplehg mercurial requests
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 14 Jul 2010 12:31:11 +0200
parents 1ef52a70f3b7
children bb8f45f6d8f9
line wrap: on
line diff
--- a/pylons_app/lib/utils.py	Wed Jul 14 02:28:51 2010 +0200
+++ b/pylons_app/lib/utils.py	Wed Jul 14 12:31:11 2010 +0200
@@ -16,6 +16,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.
+from beaker.cache import cache_region
 
 """
 Created on April 18, 2010
@@ -75,6 +76,13 @@
         log.info('%s repo is free for creation', repo_name)
         return True
 
+
+@cache_region('super_short_term', 'cached_hg_ui')
+def get_hg_ui_cached():
+    from pylons_app.model.meta import Session
+    sa = Session()
+    return sa.query(HgAppUi).all()    
+
 def make_ui(read_from='file', path=None, checkpaths=True):        
     """
     A function that will read python rc files or database
@@ -112,10 +120,7 @@
               
         
     elif read_from == 'db':
-        from pylons_app.model.meta import Session
-        sa = Session()
-            
-        hg_ui = sa.query(HgAppUi).all()
+        hg_ui = get_hg_ui_cached()
         for ui_ in hg_ui:
             baseui.setconfig(ui_.ui_section, ui_.ui_key, ui_.ui_value)