From 26f286d3fbf6298aba0fdcb9be0c158c145f473c Mon Sep 17 00:00:00 2001 From: Sebastien Robin <seb@nexedi.com> Date: Sun, 22 Apr 2007 21:23:27 +0000 Subject: [PATCH] make allowedContentTypes working 1000 times faster on important projects git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14158 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5Type/ZopePatch.py | 1 + product/ERP5Type/patches/CMFBTreeFolder.py | 59 ++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 product/ERP5Type/patches/CMFBTreeFolder.py diff --git a/product/ERP5Type/ZopePatch.py b/product/ERP5Type/ZopePatch.py index 4a16a00b8f..53d6622528 100644 --- a/product/ERP5Type/ZopePatch.py +++ b/product/ERP5Type/ZopePatch.py @@ -45,6 +45,7 @@ from Products.ERP5Type.patches import CMFCoreUtils from Products.ERP5Type.patches import PropertySheets from Products.ERP5Type.patches import CMFCoreSkinnable from Products.ERP5Type.patches import CMFCoreSkinsTool +from Products.ERP5Type.patches import CMFBTreeFolder from Products.ERP5Type.patches import OFSFolder from Products.ERP5Type.patches import HTTPRequest from Products.ERP5Type.patches import Connection diff --git a/product/ERP5Type/patches/CMFBTreeFolder.py b/product/ERP5Type/patches/CMFBTreeFolder.py new file mode 100644 index 0000000000..24c82165cd --- /dev/null +++ b/product/ERP5Type/patches/CMFBTreeFolder.py @@ -0,0 +1,59 @@ +############################################################################## +# +# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved. +# Copyright (c) 2006 Nexedi SARL and Contributors. All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# +############################################################################## + +#from Products.CMFCore.PortalFolder import PortalFolder +#from Products.CMFCore.PortalFolder import PortalFolder +try: + from Products.CMFCore.CMFBTreeFolder import CMFBTreeFolder +except ImportError: + from Products.BTreeFolder2.CMFBTreeFolder import CMFBTreeFolder +from Products.CMFCore.utils import getToolByName + +""" + This patch tries to give only portal types that are defined + in the allowed content types field. This will make the + speed of allowed content type in almost O(1) instead of O(n), + where n is the number of portal types in types tool. +""" + +def CMFBTreeFolder_allowedContentTypes(self): + """ + List type info objects for types which can be added in + this folder. + """ + result = [] + portal_types = getToolByName(self, 'portal_types') + myType = portal_types.getTypeInfo(self) + + if myType is not None: + allowed_types_to_check = [] + if myType.filter_content_types: + result = [portal_types.getTypeInfo(x) for x in + myType.allowed_content_types] + else: + if myType is not None: + for contentType in portal_types.listTypeInfo(self): + if myType.allowType( contentType.getId() ): + result.append( contentType ) + else: + result = portal_types.listTypeInfo() + + return filter( lambda typ, container=self: + typ.isConstructionAllowed( container ) + , result ) + + + +CMFBTreeFolder.allowedContentTypes = CMFBTreeFolder_allowedContentTypes + -- 2.30.9