[Checkins] SVN: five.customerize/trunk/ hold a reference to generated TTW view subclasses, to make sure they are not generated once per request. a workaround to mitigate http://dev.plone.org/plone/ticket/9218

David Glick davidglick at onenw.org
Fri Apr 30 18:06:04 EDT 2010


Log message for revision 111773:
  hold a reference to generated TTW view subclasses, to make sure they are not generated once per request. a workaround to mitigate http://dev.plone.org/plone/ticket/9218

Changed:
  U   five.customerize/trunk/CHANGES.txt
  U   five.customerize/trunk/src/five/customerize/zpt.py

-=-
Modified: five.customerize/trunk/CHANGES.txt
===================================================================
--- five.customerize/trunk/CHANGES.txt	2010-04-30 22:05:44 UTC (rev 111772)
+++ five.customerize/trunk/CHANGES.txt	2010-04-30 22:06:03 UTC (rev 111773)
@@ -4,6 +4,9 @@
 1.0b1 - Unreleased
 ------------------
 
+Fixed a memory leak by making sure that TTW view subclasses are only
+generated once, rather than once per request.
+
 Make sure TTW viewlet and portlet classes get the containing view as the
 view parameter on initialization, rather than getting themselves.
 

Modified: five.customerize/trunk/src/five/customerize/zpt.py
===================================================================
--- five.customerize/trunk/src/five/customerize/zpt.py	2010-04-30 22:05:44 UTC (rev 111772)
+++ five.customerize/trunk/src/five/customerize/zpt.py	2010-04-30 22:06:03 UTC (rev 111773)
@@ -93,8 +93,12 @@
             # that for TTW templates (which are trusted code) by
             # creating a subclass with unrestricted access to all
             # subobjects.
-            class TTWView(view_class):
-                __allow_access_to_unprotected_subobjects__ = 1
+            if hasattr(view_class, '_five_customerize_ttw_class'):
+                TTWView = view_class._five_customerize_ttw_class
+            else:
+                class TTWView(view_class):
+                    __allow_access_to_unprotected_subobjects__ = 1
+                view_class._five_customerize_ttw_class = TTWView
             self.view = TTWView(self.context, self.request)
             return self.view
 
@@ -149,8 +153,12 @@
             # that for TTW templates (which are trusted code) by
             # creating a subclass with unrestricted access to all
             # subobjects.
-            class TTWViewlet(view_class, ViewletBase):
-                __allow_access_to_unprotected_subobjects__ = 1
+            if hasattr(view_class, '_five_customerize_ttw_class'):
+                TTWViewlet = view_class._five_customerize_ttw_class
+            else:
+                class TTWViewlet(view_class, ViewletBase):
+                    __allow_access_to_unprotected_subobjects__ = 1
+                view_class._five_customerize_ttw_class = TTWViewlet
             self.viewlet = TTWViewlet(self.context, self.request, self.view, self.manager)
             return self.viewlet
 
@@ -206,8 +214,12 @@
             # that for TTW templates (which are trusted code) by
             # creating a subclass with unrestricted access to all
             # subobjects.
-            class TTWPortlet(view_class):
-                __allow_access_to_unprotected_subobjects__ = 1
+            if hasattr(view_class, '_five_customerize_ttw_class'):
+                TTWPortlet = view_class._five_customerize_ttw_class
+            else:
+                class TTWPortlet(view_class):
+                    __allow_access_to_unprotected_subobjects__ = 1
+                view_class._five_customerize_ttw_class = TTWPortlet
             self.renderer = TTWPortlet(self.context, self.request, self.view, self.manager, self.data)
             return self.renderer
 



More information about the checkins mailing list