[Zope-Checkins] SVN: Zope/trunk/ No longer opens a zodb connection
every time a ProductDispatcher is looked up,
forward ported from zope 2.10 branch r72990 and five 1.5 branch
r72986.
Rocky Burt
rocky at serverzen.com
Mon Mar 5 09:43:24 EST 2007
Log message for revision 72991:
No longer opens a zodb connection every time a ProductDispatcher is looked up, forward ported from zope 2.10 branch r72990 and five 1.5 branch r72986.
Changed:
U Zope/trunk/doc/CHANGES.txt
U Zope/trunk/lib/python/App/FactoryDispatcher.py
U Zope/trunk/lib/python/Products/Five/fiveconfigure.py
U Zope/trunk/lib/python/Products/Five/tests/test_registerpackage.py
-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt 2007-03-05 14:20:58 UTC (rev 72990)
+++ Zope/trunk/doc/CHANGES.txt 2007-03-05 14:43:23 UTC (rev 72991)
@@ -82,6 +82,9 @@
Bugs Fixed
+ - No longer opens a zodb connection every time a ProductDispatcher
+ is looked up.
+
- PageTemplate/ZRPythonExpr.py: expressions represented as unicode string
caused UnicodeDecodeErrors.
Modified: Zope/trunk/lib/python/App/FactoryDispatcher.py
===================================================================
--- Zope/trunk/lib/python/App/FactoryDispatcher.py 2007-03-05 14:20:58 UTC (rev 72990)
+++ Zope/trunk/lib/python/App/FactoryDispatcher.py 2007-03-05 14:43:23 UTC (rev 72991)
@@ -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):
Modified: Zope/trunk/lib/python/Products/Five/fiveconfigure.py
===================================================================
--- Zope/trunk/lib/python/Products/Five/fiveconfigure.py 2007-03-05 14:20:58 UTC (rev 72990)
+++ Zope/trunk/lib/python/Products/Five/fiveconfigure.py 2007-03-05 14:43:23 UTC (rev 72991)
@@ -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
Modified: Zope/trunk/lib/python/Products/Five/tests/test_registerpackage.py
===================================================================
--- Zope/trunk/lib/python/Products/Five/tests/test_registerpackage.py 2007-03-05 14:20:58 UTC (rev 72990)
+++ Zope/trunk/lib/python/Products/Five/tests/test_registerpackage.py 2007-03-05 14:43:23 UTC (rev 72991)
@@ -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()
More information about the Zope-Checkins
mailing list