Commit 63141382 authored by Vincent Pelletier's avatar Vincent Pelletier Committed by Boxiang Sun

ERP5Type: Assorted cleanups around indexation methods.

Do not check portal's isIndexable, it is checked again in ZSQLCatalog.
Directly bind superclass callable instead of doing an extra getattr +
call.
Trivial python simplifications.
Assorted coding style improvements.
Drop unhelpful comments and docstrings.
parent 34bdca66
...@@ -2790,18 +2790,9 @@ class Base( CopyContainer, ...@@ -2790,18 +2790,9 @@ class Base( CopyContainer,
security.declarePublic('immediateReindexObject') security.declarePublic('immediateReindexObject')
def immediateReindexObject(self, *args, **kw): def immediateReindexObject(self, *args, **kw):
""" if self.isIndexable:
Reindexes an object - also useful for testing
"""
root_indexable = int(getattr(self.getPortalObject(),'isIndexable',1))
if self.isIndexable and root_indexable:
#LOG("immediateReindexObject",0,self.getRelativeUrl())
# Reindex result should not depend on the user
with super_user(): with super_user():
PortalContent.reindexObject(self, *args, **kw) PortalContent.reindexObject(self, *args, **kw)
else:
pass
#LOG("No reindex now",0,self.getRelativeUrl())
security.declarePublic('recursiveImmediateReindexObject') security.declarePublic('recursiveImmediateReindexObject')
recursiveImmediateReindexObject = immediateReindexObject recursiveImmediateReindexObject = immediateReindexObject
...@@ -2833,10 +2824,10 @@ class Base( CopyContainer, ...@@ -2833,10 +2824,10 @@ class Base( CopyContainer,
activate_kw = reindex_activate_kw activate_kw = reindex_activate_kw
group_id_list = [] group_id_list = []
if kw.get("group_id", "") not in ('', None): if kw.get("group_id") not in ('', None):
group_id_list.append(kw.get("group_id", "")) group_id_list.append(kw["group_id"])
if kw.get("sql_catalog_id", "") not in ('', None): if kw.get("sql_catalog_id") not in ('', None):
group_id_list.append(kw.get("sql_catalog_id", "")) group_id_list.append(kw["sql_catalog_id"])
group_id = ' '.join(group_id_list) group_id = ' '.join(group_id_list)
self.activate(group_method_id='portal_catalog/catalogObjectList', self.activate(group_method_id='portal_catalog/catalogObjectList',
......
...@@ -1252,11 +1252,8 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn): ...@@ -1252,11 +1252,8 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn):
# Catalog related # Catalog related
security.declarePublic( 'reindexObject' ) security.declarePublic('reindexObject')
def reindexObject(self, *args, **kw): reindexObject = Base.reindexObject
"""Fixes the hierarchy structure (use of Base class)
"""
return Base.reindexObject(self, *args, **kw)
security.declareProtected(Permissions.ModifyPortalContent, security.declareProtected(Permissions.ModifyPortalContent,
'reindexObjectSecurity') 'reindexObjectSecurity')
...@@ -1265,14 +1262,13 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn): ...@@ -1265,14 +1262,13 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn):
Reindex security-related indexes on the object Reindex security-related indexes on the object
""" """
# In ERP5, simply reindex all objects, recursively by default. # In ERP5, simply reindex all objects, recursively by default.
reindex = self._getTypeBasedMethod('reindexObjectSecurity', self._getTypeBasedMethod(
'recursiveReindexObject') 'reindexObjectSecurity',
reindex(*args, **kw) 'recursiveReindexObject',
)(*args, **kw)
security.declarePublic( 'recursiveReindexObject' ) security.declarePublic('recursiveReindexObject')
def recursiveReindexObject(self, activate_kw=None, **kw): def recursiveReindexObject(self, activate_kw=None, **kw):
"""Recursively indexes the content of self.
"""
if self.isIndexable: if self.isIndexable:
if not activate_kw and self.objectCount() > REINDEX_SPLIT_COUNT: if not activate_kw and self.objectCount() > REINDEX_SPLIT_COUNT:
# If the number of objects to reindex is too high # If the number of objects to reindex is too high
...@@ -1305,10 +1301,10 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn): ...@@ -1305,10 +1301,10 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn):
activate_kw = reindex_activate_kw activate_kw = reindex_activate_kw
group_id_list = [] group_id_list = []
if kw.get("group_id", "") not in ('', None): if kw.get("group_id") not in ('', None):
group_id_list.append(kw.get("group_id", "")) group_id_list.append(kw["group_id"])
if kw.get("sql_catalog_id", "") not in ('', None): if kw.get("sql_catalog_id") not in ('', None):
group_id_list.append(kw.get("sql_catalog_id", "")) group_id_list.append(kw["sql_catalog_id"])
group_id = ' '.join(group_id_list) group_id = ' '.join(group_id_list)
self.activate(group_method_id='portal_catalog/catalogObjectList', self.activate(group_method_id='portal_catalog/catalogObjectList',
...@@ -1334,14 +1330,8 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn): ...@@ -1334,14 +1330,8 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn):
security.declarePublic( 'recursiveImmediateReindexObject' ) security.declarePublic( 'recursiveImmediateReindexObject' )
def recursiveImmediateReindexObject(self, **kw): def recursiveImmediateReindexObject(self, **kw):
""" if self.isIndexable:
Applies immediateReindexObject recursively
"""
# Reindex self
root_indexable = int(getattr(self.getPortalObject(),'isIndexable',1))
if self.isIndexable and root_indexable:
self.immediateReindexObject(**kw) self.immediateReindexObject(**kw)
# Reindex contents
for c in self.objectValues(): for c in self.objectValues():
if getattr(aq_base(c), if getattr(aq_base(c),
'recursiveImmediateReindexObject', None) is not None: 'recursiveImmediateReindexObject', None) is not None:
......
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