Commit 95e3eaec authored by Vincent Pelletier's avatar Vincent Pelletier

CMFCategory: Do not index any Base Category as a related document.

Without this change, "source/a/b" in non-strict mode indexes:
  (document.uid, source.uid, b.uid, 1)
  (document.uid, source.uid, a.uid, 0)
  (document.uid, source.uid, source.uid, 0)
This last line does not contain anything which cannot be found by looking
at the base category uid column, so it is wasting disk (and index) space,
costing performance.
But keep indexing a Base Category document if is it not the base category
for considered relation. It is not clear whether stopping indexation at the
first encountered Base Category document is intentional, or if recursion
should only stop when reaching the base category of considered relation.
With this change, "source/a/b" in non-strict mode indexes:
  (document.uid, source.uid, b.uid, 1)
  (document.uid, source.uid, a.uid, 0)
removing the redundancy.
parent 2b20a1d8
...@@ -362,7 +362,10 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -362,7 +362,10 @@ class CategoryTool( UniqueObject, Folder, Base ):
# XXX we should also go up in some other cases.... # XXX we should also go up in some other cases....
# ie. when some documents act as categories # ie. when some documents act as categories
o = o.aq_parent # We want acquisition here without aq_inner o = o.aq_parent # We want acquisition here without aq_inner
uid_set.add((o.getUid(), bo_uid, 0)) # Non Strict Membership o_uid = o.getUid()
if o_uid == bo_uid:
break
uid_set.add((o_uid, bo_uid, 0)) # Non Strict Membership
except (KeyError, AttributeError): except (KeyError, AttributeError):
LOG('WARNING: CategoriesTool',0, 'Unable to find uid for %s' % path) LOG('WARNING: CategoriesTool',0, 'Unable to find uid for %s' % path)
return list(uid_set) # cast to list for <dtml-in> return list(uid_set) # cast to list for <dtml-in>
...@@ -1631,12 +1634,22 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1631,12 +1634,22 @@ class CategoryTool( UniqueObject, Folder, Base ):
""" """
if base_category is None: if base_category is None:
base_category = context.getBaseCategoryId() base_category = context.getBaseCategoryId()
sql_kw = { if context.portal_type == 'Base Category' and context.getId() == base_category:
( # Looking for all documents which are member of context a
# (Base Category) via a relationship of its own type: assume this means
# caller wants to retrieve documents having any document related via a
# relationship of the type of context.
# XXX: ignoring "strict*" argument. It does not have much meaning in
# this case anyway.
key = 'category.base_category_uid'
else:
key = (
'strict_' 'strict_'
if strict_membership or strict else if strict_membership or strict else
'default_' 'default_'
) + base_category + '_uid': context.getUid(), ) + base_category + '_uid'
sql_kw = {
key: context.getUid(),
} }
if portal_type: if portal_type:
sql_kw['portal_type'] = portal_type sql_kw['portal_type'] = portal_type
......
...@@ -333,7 +333,6 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -333,7 +333,6 @@ class TestCMFCategory(ERP5TypeTestCase):
[ [
(cat2.getUid(), basecat.getUid(), 1), (cat2.getUid(), basecat.getUid(), 1),
(cat1.getUid(), basecat.getUid(), 0), (cat1.getUid(), basecat.getUid(), 0),
(basecat.getUid(), basecat.getUid(), 0),
], ],
) )
self.assertItemsEqual( self.assertItemsEqual(
...@@ -344,7 +343,6 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -344,7 +343,6 @@ class TestCMFCategory(ERP5TypeTestCase):
(cat22.getUid(), basecat.getUid(), 1), (cat22.getUid(), basecat.getUid(), 1),
(cat2.getUid(), basecat.getUid(), 0), (cat2.getUid(), basecat.getUid(), 0),
(cat1.getUid(), basecat.getUid(), 0), (cat1.getUid(), basecat.getUid(), 0),
(basecat.getUid(), basecat.getUid(), 0),
], ],
) )
# Non-canonical path # Non-canonical path
...@@ -356,7 +354,6 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -356,7 +354,6 @@ class TestCMFCategory(ERP5TypeTestCase):
(cat3.getUid(), basecat.getUid(), 1), (cat3.getUid(), basecat.getUid(), 1),
(cat2.getUid(), basecat.getUid(), 0), (cat2.getUid(), basecat.getUid(), 0),
(cat1.getUid(), basecat.getUid(), 0), (cat1.getUid(), basecat.getUid(), 0),
(basecat.getUid(), basecat.getUid(), 0),
], ],
) )
# Strict, implicit base category # Strict, implicit base category
...@@ -613,12 +610,12 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -613,12 +610,12 @@ class TestCMFCategory(ERP5TypeTestCase):
c1 = bc.newContent(portal_type='Category', id='1') c1 = bc.newContent(portal_type='Category', id='1')
self.tic() self.tic()
self.assertItemsEqual(pc.getRelatedValueList(bc), [bc, c1]) self.assertItemsEqual(pc.getRelatedValueList(bc), [bc])
self.assertItemsEqual(pc.getRelatedValueList(c1), [c1]) self.assertItemsEqual(pc.getRelatedValueList(c1), [c1])
c11 = c1.newContent(portal_type='Category', id='1') c11 = c1.newContent(portal_type='Category', id='1')
self.tic() self.tic()
self.assertItemsEqual(pc.getRelatedValueList(bc), [bc, c1, c11]) self.assertItemsEqual(pc.getRelatedValueList(bc), [bc])
self.assertItemsEqual(pc.getRelatedValueList(c1), [c1, c11]) self.assertItemsEqual(pc.getRelatedValueList(c1), [c1, c11])
self.assertItemsEqual(pc.getRelatedValueList(c11), [c11]) self.assertItemsEqual(pc.getRelatedValueList(c11), [c11])
...@@ -671,6 +668,7 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -671,6 +668,7 @@ class TestCMFCategory(ERP5TypeTestCase):
"""Test strict_membership parameter to Category Member Value List """ """Test strict_membership parameter to Category Member Value List """
portal_categories = self.getCategoryTool() portal_categories = self.getCategoryTool()
organisation = self.getOrganisationModule().newContent( organisation = self.getOrganisationModule().newContent(
test0='region/europe', test1='region',
portal_type='Organisation', region='europe/west/france') portal_type='Organisation', region='europe/west/france')
self.tic() self.tic()
...@@ -681,7 +679,6 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -681,7 +679,6 @@ class TestCMFCategory(ERP5TypeTestCase):
base_category='region', base_category='region',
strict_membership=0, strict_membership=0,
portal_type='Organisation')], [organisation]) portal_type='Organisation')], [organisation])
self.assertEqual([x.getObject() for x in self.assertEqual([x.getObject() for x in
portal_categories.getCategoryMemberValueList( portal_categories.getCategoryMemberValueList(
portal_categories.region.europe.west.france, portal_categories.region.europe.west.france,
...@@ -695,7 +692,6 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -695,7 +692,6 @@ class TestCMFCategory(ERP5TypeTestCase):
base_category='region', base_category='region',
strict_membership=0, strict_membership=0,
portal_type='Organisation')], [organisation]) portal_type='Organisation')], [organisation])
self.assertEqual([x.getObject() for x in self.assertEqual([x.getObject() for x in
portal_categories.getCategoryMemberValueList( portal_categories.getCategoryMemberValueList(
portal_categories.region.europe.west, portal_categories.region.europe.west,
...@@ -709,6 +705,32 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -709,6 +705,32 @@ class TestCMFCategory(ERP5TypeTestCase):
base_category='region', base_category='region',
portal_type='Organisation')], [organisation]) portal_type='Organisation')], [organisation])
self.assertEqual([x.getObject() for x in
portal_categories.getCategoryMemberValueList(
portal_categories.region,
base_category='test0',
strict_membership=0,
portal_type='Organisation')], [organisation])
self.assertEqual([x.getObject() for x in
portal_categories.getCategoryMemberValueList(
portal_categories.region,
base_category='test0',
strict_membership=1,
portal_type='Organisation')], [])
self.assertEqual([x.getObject() for x in
portal_categories.getCategoryMemberValueList(
portal_categories.region,
base_category='test1',
strict_membership=0,
portal_type='Organisation')], [organisation])
self.assertEqual([x.getObject() for x in
portal_categories.getCategoryMemberValueList(
portal_categories.region,
base_category='test1',
strict_membership=1,
portal_type='Organisation')], [organisation])
def test_20_CategoryChildTitleAndIdItemList(self): def test_20_CategoryChildTitleAndIdItemList(self):
"""Tests getCategoryChildTitleAndIdItemList.""" """Tests getCategoryChildTitleAndIdItemList."""
base_cat = self.getCategoryTool().newContent(portal_type='Base Category') base_cat = self.getCategoryTool().newContent(portal_type='Base Category')
......
...@@ -1227,17 +1227,18 @@ class TestInventoryList(InventoryAPITestCase): ...@@ -1227,17 +1227,18 @@ class TestInventoryList(InventoryAPITestCase):
self.other_node.getUid()), self.other_node.getUid()),
group_by=('use_uid', ), group_by=('use_uid', ),
select_list=['use_uid']) select_list=['use_uid'])
self.assertEqual(4, len(inventory_list)) self.assertEqual(3, len(inventory_list))
self.assertTrue(hasattr(inventory_list[0], 'use_uid')) self.assertTrue(hasattr(inventory_list[0], 'use_uid'))
self.assertEqual([r.inventory for r in inventory_list self.assertEqual([r.inventory for r in inventory_list
if r.use_uid == use.use1.use11.getUid()], [5]) if r.use_uid == use.use1.use11.getUid()], [5])
self.assertEqual([r.inventory for r in inventory_list self.assertEqual([r.inventory for r in inventory_list
if r.use_uid == use.use1.use12.getUid()], [11]) if r.use_uid == use.use1.use12.getUid()], [11])
# the summary lines # the summary line
self.assertEqual([r.inventory for r in inventory_list self.assertEqual([r.inventory for r in inventory_list
if r.use_uid == use.use1.getUid()], [11+5]) if r.use_uid == use.use1.getUid()], [11+5])
self.assertEqual([r.inventory for r in inventory_list # no summary for base category
if r.use_uid == use.getUid()], [11+5]) self.assertEqual([r.use_uid for r in inventory_list
if r.use_uid == use.getUid()], [])
# the name of a column can also be used, from stock or other tables # the name of a column can also be used, from stock or other tables
inventory_list = getInventoryList(node_uid=(self.node.getUid(), inventory_list = getInventoryList(node_uid=(self.node.getUid(),
......
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