Commit f60ccc48 authored by Julien Muchembled's avatar Julien Muchembled

Fix performance regression caused by [30213] (when creating objects)

In objectValues, doing nothing is a BTree is not initialized speeds up
_setObject by about ~1 %. But a third code path must be added for OFS Folders
(here, ERP5 Category Tool).

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@30252 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 40d03335
...@@ -36,6 +36,7 @@ from AccessControl import ClassSecurityInfo ...@@ -36,6 +36,7 @@ from AccessControl import ClassSecurityInfo
from Acquisition import aq_base from Acquisition import aq_base
from Products.ERP5Type.Globals import InitializeClass from Products.ERP5Type.Globals import InitializeClass
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from Products.ERP5Type.Core.Folder import OFS_HANDLER
from Products.ERP5Type.CopySupport import CopyContainer from Products.ERP5Type.CopySupport import CopyContainer
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from Products.ERP5Type.Cache import caching_instance_method from Products.ERP5Type.Cache import caching_instance_method
...@@ -52,6 +53,7 @@ class CategoryTool(CopyContainer, CMFCategoryTool, BaseTool): ...@@ -52,6 +53,7 @@ class CategoryTool(CopyContainer, CMFCategoryTool, BaseTool):
meta_type = 'ERP5 Categories' meta_type = 'ERP5 Categories'
portal_type = 'Category Tool' portal_type = 'Category Tool'
allowed_types = ( 'ERP5 Base Category',) allowed_types = ( 'ERP5 Base Category',)
_folder_handler = OFS_HANDLER
# Declarative Security # Declarative Security
security = ClassSecurityInfo() security = ClassSecurityInfo()
......
...@@ -367,6 +367,8 @@ class FolderMixIn(ExtensionClass.Base): ...@@ -367,6 +367,8 @@ class FolderMixIn(ExtensionClass.Base):
else: else:
return None return None
OFS_HANDLER = 0
BTREE_HANDLER = 1 BTREE_HANDLER = 1
HBTREE_HANDLER = 2 HBTREE_HANDLER = 2
...@@ -1386,38 +1388,31 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn, ...@@ -1386,38 +1388,31 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn,
**kw): **kw):
# Returns list of objects contained in this folder. # Returns list of objects contained in this folder.
# (no docstring to prevent publishing) # (no docstring to prevent publishing)
if meta_type is not None: if meta_type is not None:
spec = meta_type spec = meta_type
# when an object inherits from Folder after it was instanciated, it lacks if self._folder_handler == BTREE_HANDLER:
# its BTreeFolder properties. if self._tree is None:
# if getattr(self, '_tree', None) is None: return []
# try: object_list = CMFBTreeFolder.objectValues(self, spec=spec)
# self._initBTrees() elif self._folder_handler == HBTREE_HANDLER:
# except AttributeError:
# from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2Base
# BTreeFolder2Base.__init__(self, self.getId())
if self._folder_handler == HBTREE_HANDLER:
if self._htree is None: if self._htree is None:
object_list = [] return []
else: if 'base_id' in kw:
if kw.has_key("base_id"):
object_list = CMFHBTreeFolder.objectValues(self, base_id=kw['base_id']) object_list = CMFHBTreeFolder.objectValues(self, base_id=kw['base_id'])
else: else:
object_list = CMFHBTreeFolder.objectValues(self) object_list = CMFHBTreeFolder.objectValues(self)
else: else:
object_list = CMFBTreeFolder.objectValues(self, spec=spec) object_list = map(self._getOb, self.objectIds(spec))
if portal_type is not None: if portal_type is not None:
if type(portal_type) == type(''): if isinstance(portal_type, str):
portal_type = (portal_type,) portal_type = (portal_type,)
object_list = filter(lambda x: x.getPortalType() in portal_type, object_list = filter(lambda x: x.getPortalType() in portal_type,
object_list) object_list)
if checked_permission is not None: if checked_permission is not None:
checkPermission = getSecurityManager().checkPermission checkPermission = getSecurityManager().checkPermission
object_list = [o for o in object_list if checkPermission(checked_permission, o)] object_list = [o for o in object_list
object_list = sortValueList(object_list, sort_on, sort_order, **kw) if checkPermission(checked_permission, o)]
return object_list return sortValueList(object_list, sort_on, sort_order, **kw)
security.declareProtected( Permissions.AccessContentsInformation, security.declareProtected( Permissions.AccessContentsInformation,
'contentValues' ) 'contentValues' )
......
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