Commit 26f286d3 authored by Sebastien Robin's avatar Sebastien Robin

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
parent cec6ce61
......@@ -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
......
##############################################################################
#
# 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment