Commit 13257f24 authored by iv's avatar iv

ERP5Workflow: PERF: improve ERP5PersistentMapping performance

parent 4da760e5
......@@ -43,15 +43,9 @@ class ERP5PersistentMappingFolder(PortalFolderBase):
except KeyError:
raise AttributeError(name)
def __len__(self):
return self.objectCount()
def _initPersistentObjects(self, object_id=None):
def _initPersistentObjects(self):
self._cleanup()
if object_id is None:
self.__init__(self.id)
else:
self.__init__(object_id)
self.__init__(self.id)
security.declareProtected(Permissions.AccessContentsInformation, 'get')
def get(self, name, default=None):
......@@ -92,12 +86,12 @@ class ERP5PersistentMappingFolder(PortalFolderBase):
def objectCount(self):
return len(self._object_dict)
__len__ = objectCount
def objectItems(self, spec=None):
assert(spec is None)
return self._object_dict.items()
def objectIds_d(self, t=None):
assert(t is None)
return objectIds(self, t)
security.declareProtected( Permissions.AccessContentsInformation,
......@@ -110,6 +104,7 @@ class ERP5PersistentMappingFolder(PortalFolderBase):
if spec is not None:
if isinstance(spec, str):
spec = (spec,)
# XXX(WORKFLOW): remove this and use portal_type only
# hack to get the portal type for a specified meta_type
portal_type = [meta_type[5:] for meta_type in spec
if meta_type.startswith('ERP5 ')]
......@@ -120,13 +115,14 @@ class ERP5PersistentMappingFolder(PortalFolderBase):
if portal_type is not None:
if isinstance(portal_type, str):
portal_type = (portal_type,)
object_list = filter(lambda x: x.getPortalType() in portal_type,
object_list)
object_list = [x for x in object_list if x.getPortalType() in portal_type]
if checked_permission is not None:
checkPermission = getSecurityManager().checkPermission
object_list = [o for o in object_list
if checkPermission(checked_permission, o)]
return [x.__of__(self) for x in sortValueList(object_list, sort_on, sort_order, **kw)]
return [x.__of__(self) for x in sortValueList(object_list, sort_on,
sort_order, **kw)]
security.declareProtected(Permissions.AccessContentsInformation,
'keys', 'items', 'values')
......@@ -142,12 +138,9 @@ class ERP5PersistentMappingFolder(PortalFolderBase):
id = v
# If an object by the given id already exists, remove it.
if id in self:
if self.has_key(id):
self._delObject(id)
if not suppress_events:
notify(ObjectWillBeAddedEvent(ob, self, id))
self._setOb(id, ob)
ob = self._getOb(id)
......@@ -165,15 +158,11 @@ class ERP5PersistentMappingFolder(PortalFolderBase):
if userid is not None:
ob.manage_setLocalRoles(userid, ['Owner'])
if not suppress_events:
notify(ObjectAddedEvent(ob, self, id))
notifyContainerModified(self)
compatibilityCall('manage_afterAdd', ob, ob, self)
return id
def _cleanup(self):
# XXX(WORKFLOW): just do something on _object_dict, create another function
# for conversion
cleaned = False
for attribute in ('_tree', '_mt_index', '_count'):
try:
......@@ -214,6 +203,6 @@ class ERP5PersistentMappingFolder(PortalFolderBase):
return ()
def _checkId(self, id, allow_dup=0):
if self._object_dict is not None and not allow_dup and id in self._object_dict:
if not allow_dup and self.has_key(id):
raise BadRequestException('The id "%s" is invalid--'
'it is already in use.' % id)
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