[Zope-dev] Re: TypesTool speedup

Rocky rocky at serverzen.com
Sun Mar 4 14:41:04 EST 2007


On Mar 4, 1:49 pm, "Alec Mitchell" <a... at columbia.edu> wrote:
> Looking at the changes rocky made, I don't see why allowing external
> methods from non-Products should require making the whole process
> completely dynamic on every call.  The old mechanism of storing the
> product list should be put back in place, along with the addition of
> non-Product information to these results.

Following this message are two patches I'm ready to apply.  One for
Five and one for Zope2.  The lookup is still dynamic, but at least it
doesn't open a zodb connection everytime anymore.  It more closely
resembles what was trying to be done originally, and that is to look
up factory info from the Products.* package.

I'm prepared to commit this but posting it here for review first.
Plus ... what is the policy for updating the Five svn:external for
Zope ? (ie right now it points at Five 1.5.2 tag)

Regards,
Rocky

Five Patch:

Index: fiveconfigure.py
===================================================================
--- fiveconfigure.py	(revision 72973)
+++ fiveconfigure.py	(working copy)
@@ -218,6 +218,11 @@
         if init_func is not None:
             newContext = ProductContext(product, app, module_)
             init_func(newContext)
+
+        registered_packages = getattr(Products,
'_registered_packages', None)
+        if registered_packages is None:
+            registered_packages = Products._registered_packages = []
+        registered_packages.append(module_)
     finally:
         try:
             import transaction
Index: tests/test_registerpackage.py
===================================================================
--- tests/test_registerpackage.py	(revision 72973)
+++ tests/test_registerpackage.py	(working copy)
@@ -65,7 +65,11 @@
       >>> 'pythonproduct2' in product_listing
       True

+    Make sure it also shows up in ``Products._registered_packages``.

+      >>> [x.__name__ for x in getattr(Products,
'_registered_packages', [])]
+      ['pythonproduct2']
+
     Clean up:

       >>> tearDown()
Index: CHANGES.txt
===================================================================
--- CHANGES.txt	(revision 72973)
+++ CHANGES.txt	(working copy)
@@ -2,6 +2,14 @@
 Five Changes
 ============

+Five 1.5.x (svn/unreleased)
+===========================
+
+* Added change to registerPackage directive so that it stores the
newly
+  registered packages on the Products package object for faster
reference.
+  This means code that looks this up (ie Zope2's FactoryDispatcher)
no longer
+  has to open a zodb connection each time.
+
 Five 1.5.2 (2007-01-10)
 =======================


Zope2 Patch:

Index: lib/python/App/FactoryDispatcher.py
===================================================================
--- lib/python/App/FactoryDispatcher.py	(revision 72972)
+++ lib/python/App/FactoryDispatcher.py	(working copy)
@@ -26,32 +26,15 @@
     zope2 packages and those without the Products namespace package.
     """

-    old_product_packages = {}
+    packages = {}
     for x in dir(Products):
         m = getattr(Products, x)
         if isinstance(m, types.ModuleType):
-            old_product_packages[x] = m
+            packages[x] = m
+
+    for m in getattr(Products, '_registered_packages', []):
+        packages[m.__name__] = m

-    packages = {}
-    app = Zope2.app()
-    try:
-        products = app.Control_Panel.Products
-
-        for product_id in products.objectIds():
-            product = products[product_id]
-            if hasattr(product, 'package_name'):
-                pos = product.package_name.rfind('.')
-                if pos > -1:
-                    packages[product_id] =
__import__(product.package_name,
-                                                      globals(), {},
-
product.package_name[pos+1:])
-                else:
-                    packages[product_id] =
__import__(product.package_name)
-            elif old_product_packages.has_key(product_id):
-                packages[product_id] =
old_product_packages[product_id]
-    finally:
-        app._p_jar.close()
-
     return packages

 class ProductDispatcher(Acquisition.Implicit):



More information about the Zope-Dev mailing list