Commit 13257f24 authored by iv's avatar iv

ERP5Workflow: PERF: improve ERP5PersistentMapping performance

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