[Mpuls-commits] r270 - in wasko/trunk: . waskaweb/lib waskaweb/model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Feb 19 12:15:37 CET 2009


Author: teichmann
Date: 2009-02-19 12:15:36 +0100 (Thu, 19 Feb 2009)
New Revision: 270

Modified:
   wasko/trunk/ChangeLog.txt
   wasko/trunk/waskaweb/lib/base.py
   wasko/trunk/waskaweb/lib/security.py
   wasko/trunk/waskaweb/model/casedocument.py
Log:
Added request bases page cache.


Modified: wasko/trunk/ChangeLog.txt
===================================================================
--- wasko/trunk/ChangeLog.txt	2009-02-19 11:00:50 UTC (rev 269)
+++ wasko/trunk/ChangeLog.txt	2009-02-19 11:15:36 UTC (rev 270)
@@ -1,3 +1,15 @@
+2009-02-19	Sascha L. Teichmann <teichmann at intevation.de>
+
+	Cache pages on request base to make global value analysis
+	more efficient. Which is particular import for the phase checking stuff.
+
+	* waskaweb/lib/security.py: Print traces to stderr instead to stdout
+
+	* waskaweb/model/casedocument.py: Use a thread local cache to store
+	  pages of current document.
+
+	* waskaweb/lib/base.py: Added enter/leave code for the page cache.
+
 2009-02-19	Torsten Irlaender  <torsten.irlaender at intevation.de>
 
 	First adoption of the adele evaluation for WASKO.

Modified: wasko/trunk/waskaweb/lib/base.py
===================================================================
--- wasko/trunk/waskaweb/lib/base.py	2009-02-19 11:00:50 UTC (rev 269)
+++ wasko/trunk/waskaweb/lib/base.py	2009-02-19 11:15:36 UTC (rev 270)
@@ -33,8 +33,9 @@
 from pylons.i18n                import _, ungettext, N_
 from pylons.templating          import render
 
-import waskaweb.lib.helpers     as h
-import waskaweb.model           as model
+import waskaweb.lib.helpers        as h
+import waskaweb.model              as model
+import waskaweb.model.casedocument as casedocument
 
 import waskaweb.lib.db          as db
 
@@ -54,8 +55,10 @@
 IDENTITY_CHANGED = "Ihre Identitaet hat sich geaendert."
 
 class BaseController(WSGIController):
+
     def __init__(self):
-        self.db = None
+        self.db         = None
+        self.page_cache = None
 
     def __before__(self):
 
@@ -108,6 +111,10 @@
                 #print >> sys.stderr, "Redirect to: '%s'" % request.path_info
                 redirect_to(h.url_for(controller='/waska', action='login'))
 
+        self.page_cache = casedocument.PageCache()
+        casedocument.enter(self.page_cache)
+
+
     def __call__(self, environ, start_response):
         """Invoke the Controller"""
         # WSGIController.__call__ dispatches to the Controller method
@@ -117,6 +124,10 @@
         try:
             return WSGIController.__call__(self, environ, start_response)
         finally:
+            _cache = self.page_cache
+            if _cache:
+                self.page_cache = None
+                casedocument.leave(_cache)
             _db = self.db
             if _db:
                 self.db = None

Modified: wasko/trunk/waskaweb/lib/security.py
===================================================================
--- wasko/trunk/waskaweb/lib/security.py	2009-02-19 11:00:50 UTC (rev 269)
+++ wasko/trunk/waskaweb/lib/security.py	2009-02-19 11:15:36 UTC (rev 270)
@@ -197,7 +197,7 @@
                 except StandardError, e: 
                     print e 
     else:
-        print "No file mapping file found named: %s" % fname
+        print >> sys.stderr, "No file mapping file found named: %s" % fname
 
 def getDbName():
     dbname = None

Modified: wasko/trunk/waskaweb/model/casedocument.py
===================================================================
--- wasko/trunk/waskaweb/model/casedocument.py	2009-02-19 11:00:50 UTC (rev 269)
+++ wasko/trunk/waskaweb/model/casedocument.py	2009-02-19 11:15:36 UTC (rev 270)
@@ -33,20 +33,44 @@
 from waskaweb.model.data           import PageNode
 from waskaweb.model.datapage       import PageStore, EmptyPageStore
 
+from paste.registry import StackedObjectProxy
+
+page_cache = StackedObjectProxy(name="waska.pagecache")
+
+def enter(cache):
+    page_cache._push_object(cache)
+
+def leave(cache=None):
+    page_cache._pop_object(cache)
+
+class PageCache(object):
+
+    def __init__(self):
+        self.pages = {}
+
+    def getPageStore(self, formed, name, ds_id = None):
+        try:
+            return self.pages[name]
+        except KeyError:
+            nc = formed.findByClassAndName(PageNode, name)
+            db_view = "%s_view" % name
+            page = PageStore(db_view, nc, ds_id)
+            self.pages[name] = page
+            return page
+
+
 class CaseDocument(Document):
     def __init__(self, root=None):
         Document.__init__(self, root)
 
-    def getPageStore(self, name, ds_id=None, proxy=None, no_data=False):
-        db_view = "%s_view" % name
-        nc = self.findByClassAndName(PageNode, name)
-        if proxy:
-            proxy.set(nc)
-            nc = proxy
-        if no_data:
-            page = EmptyPageStore(db_view, nc, ds_id)
-        else:
-            page = PageStore(db_view, nc, ds_id)
-        return page
+    #def getPageStore(self, name, ds_id=None, proxy=None, no_data=False):
+    def getPageStore(self, name, ds_id=None, no_data=False):
 
+        if no_data: # XXX: urcan mode!
+            db_view = "%s_view" % name
+            nc = self.findByClassAndName(PageNode, name)
+            return EmptyPageStore(db_view, nc, ds_id)
+
+        return page_cache.getPageStore(self, name, ds_id)
+
 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:



More information about the Mpuls-commits mailing list