Commit d85e2c38 authored by Vincent Pelletier's avatar Vincent Pelletier

CategoryTool: Use catalog instead of ZSQLMethod

The main purpose is to stop calling buildSQLSelector so it can be removed.
Remove Base_zSearchRelatedObjectsByCategoryList.
Also, discard a superfluous comment in testArchive which references the
discarded ZSQLMethod, for consistency.
Fixes an existing failure in testArchive.
parent cd1859ef
......@@ -1347,6 +1347,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
# Base Category may not be related, besides sub categories
relative_url = context.getRelativeUrl()
local_index_dict = {}
is_any_base_category = False
if isinstance(context, BaseCategory):
category_list = relative_url,
else:
......@@ -1355,15 +1356,34 @@ class CategoryTool( UniqueObject, Folder, Base ):
base_category_list = base_category_list,
elif base_category_list is () or base_category_list is None:
base_category_list = self.getBaseCategoryList()
is_any_base_category = True
for base_category in base_category_list:
if self[base_category].isRelatedLocallyIndexed():
category = base_category + '/'
local_index_dict[base_category] = '' \
if relative_url.startswith(category) else category
else:
elif not is_any_base_category:
# If base_category_list contains all base categories, and the
# relation is not locally indexed, then just do not apply any
# relational condition. This assumes relation membership
# conditions would not exclude any document, iow there are no
# indexed relation which has a non-existing base category.
category_list.append("%s/%s" % (base_category, relative_url))
search = self.getPortalObject().Base_zSearchRelatedObjectsByCategoryList
portal_catalog = context.getPortalObject().portal_catalog
def search(category_list, portal_type, strict_membership):
catalog_kw = portal_catalog.getCategoryParameterDict(
category_list=category_list,
strict_membership=strict_membership,
)
inner_join_list = catalog_kw.keys()
if portal_type is not None:
catalog_kw['portal_type'] = portal_type
return portal_catalog.unrestrictedSearchResults(
select_list=['relative_url', 'portal_type'],
inner_join_list=inner_join_list,
**catalog_kw
)
result_dict = {}
if local_index_dict:
# For some base categories, lookup indexes in ZODB.
......@@ -1399,7 +1419,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
# Update local index with results from catalog for backward
# compatibility. But no need to do it several times in the same
# transaction.
for r in search(category_list=category,
for r in search(category_list=[category],
portal_type=None,
strict_membership=strict_membership):
r = r.relative_url
......@@ -1459,10 +1479,23 @@ class CategoryTool( UniqueObject, Folder, Base ):
else:
# Catalog-only search.
result = []
if category_list:
for r in search(category_list=category_list,
if category_list or is_any_base_category:
if is_any_base_category:
catalog_kw = {
('strict__' if strict_membership else '') +
'any__uid': context.getUid(),
}
if portal_type is not None:
catalog_kw['portal_type'] = portal_type
from_catalog_result_list = portal_catalog.unrestrictedSearchResults(
select_list=['relative_url', 'portal_type'],
**catalog_kw
)
else:
from_catalog_result_list = search(category_list=category_list,
portal_type=portal_type,
strict_membership=strict_membership):
strict_membership=strict_membership)
for r in from_catalog_result_list:
if r.relative_url not in result_dict:
try:
result.append(self.unrestrictedTraverse(r.path))
......
SELECT DISTINCT catalog.uid, path, relative_url, portal_type
FROM catalog, category
WHERE catalog.uid = category.uid
<dtml-if portal_type>
AND <dtml-sqltest portal_type type="string" multiple>
</dtml-if>
AND (<dtml-var "portal_categories.buildSQLSelector(category_list)">)
<dtml-if strict_membership>
AND category.category_strict_membership = 1
</dtml-if>
<dtml-if where_expression>
AND <dtml-var where_expression>
</dtml-if>
<dtml-if order_by_expression>
ORDER BY
<dtml-var order_by_expression>
</dtml-if>
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="SQL" module="Products.ZSQLMethods.SQL"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>allow_simple_one_argument_traversal</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>arguments_src</string> </key>
<value> <string>category_list\r\n
portal_type\r\n
strict_membership\r\n
where_expression\r\n
order_by_expression</string> </value>
</item>
<item>
<key> <string>cache_time_</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>class_file_</string> </key>
<value> <string>ZSQLCatalog.zsqlbrain</string> </value>
</item>
<item>
<key> <string>class_name_</string> </key>
<value> <string>ZSQLBrain</string> </value>
</item>
<item>
<key> <string>connection_hook</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>connection_id</string> </key>
<value> <string>erp5_sql_connection</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_zSearchRelatedObjectsByCategoryList</string> </value>
</item>
<item>
<key> <string>max_cache_</string> </key>
<value> <int>100</int> </value>
</item>
<item>
<key> <string>max_rows_</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Search Category</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -360,7 +360,6 @@ class TestArchive(InventoryAPITestCase):
# with a static variable.
depth.append(None)
assert not portal_type, portal_type
# the following line calls Base_zSearchRelatedObjectsByCategoryList
object.getSourceDecisionRelatedValueList()
bc, = base_category_list
depth.pop()
......@@ -373,7 +372,7 @@ class TestArchive(InventoryAPITestCase):
self.assertEqual(['green'], getSecurityManager().getUser().getGroups())
self.portal.portal_caches.clearAllCache()
PortalTestCase.login(self, person.Person_getUserId())
unittest.expectedFailure(self.assertEqual)(
self.assertEqual(
['green'], getSecurityManager().getUser().getGroups())
finally:
skin.manage_delObjects(script_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