Commit d8dfa6c7 authored by Vincent Pelletier's avatar Vincent Pelletier

CategoryTool: Factorise out-of-ZODB related object lookup

To prepare for extension.
parent 87ab190b
...@@ -1364,10 +1364,10 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1364,10 +1364,10 @@ class CategoryTool( UniqueObject, Folder, Base ):
category_list.append("%s/%s" % (base_category, relative_url)) category_list.append("%s/%s" % (base_category, relative_url))
search = self.getPortalObject().Base_zSearchRelatedObjectsByCategoryList search = self.getPortalObject().Base_zSearchRelatedObjectsByCategoryList
result_dict = {}
if local_index_dict: if local_index_dict:
# For some base categories, lookup indexes in ZODB. # For some base categories, lookup indexes in ZODB.
recurse = isinstance(context, Category) and not strict_membership recurse = isinstance(context, Category) and not strict_membership
result_dict = {}
def check_local(): def check_local():
r = set(getattr(related, base_category, ())) r = set(getattr(related, base_category, ()))
r.difference_update(result_dict) r.difference_update(result_dict)
...@@ -1456,22 +1456,14 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1456,22 +1456,14 @@ class CategoryTool( UniqueObject, Folder, Base ):
not portal_type or ob.getPortalType() in portal_type)] not portal_type or ob.getPortalType() in portal_type)]
# Finish with base categories that are only indexed in catalog, # Finish with base categories that are only indexed in catalog,
# making sure we don't return duplicate values. # making sure we don't return duplicate values.
if category_list:
for r in search(category_list=category_list,
portal_type=portal_type,
strict_membership=strict_membership):
if r.relative_url not in result_dict:
try:
result.append(self.unrestrictedTraverse(r.path))
except KeyError:
pass
else: else:
# Catalog-only search. # Catalog-only search.
result = [] result = []
if category_list:
for r in search(category_list=category_list, for r in search(category_list=category_list,
portal_type=portal_type, portal_type=portal_type,
strict_membership=strict_membership): strict_membership=strict_membership):
if r.relative_url not in result_dict:
try: try:
result.append(self.unrestrictedTraverse(r.path)) result.append(self.unrestrictedTraverse(r.path))
except KeyError: except KeyError:
......
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