Commit c09bea2a authored by Jérome Perrin's avatar Jérome Perrin

erp5_mysql_innodb_catalog : Normalize DELETE then INSERT indexation methods

See discussions in !257 from background.

Here we try to reduce the differences in indexation methods that use `DELETE` and then `INSERT` (the one who does not always index the same number of rows).

In `z_catalog_predicate_list` the `DELETE` was missing, so in the case of predicate which stopped being a predicate, that predicate was never removed from the table.


/reviewed-on !294
parents d708bd87 fbfd8323
DELETE FROM DELETE FROM
item item
WHERE WHERE
<dtml-in uid> <dtml-sqltest uid type="int" multiple>
uid=<dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>
</dtml-in>
;
<dtml-var "'\0'"> <dtml-var sql_delimiter>
<dtml-let movement_list="[]" uid_dict="{}"> <dtml-let movement_list="[]" uid_dict="{}">
<dtml-in prefix="loop" expr="_.range(_.len(uid))"> <dtml-in prefix="loop" expr="_.range(_.len(uid))">
...@@ -16,7 +13,7 @@ WHERE ...@@ -16,7 +13,7 @@ WHERE
</dtml-if> </dtml-if>
</dtml-in> </dtml-in>
<dtml-if expr="_.len(movement_list) > 0"> <dtml-if expr="_.len(movement_list) > 0">
REPLACE INTO INSERT INTO
item item
VALUES VALUES
<dtml-in prefix="loop" expr="movement_list"> <dtml-in prefix="loop" expr="movement_list">
......
DELETE FROM `measure` WHERE DELETE FROM `measure` WHERE
<dtml-sqltest uid column="resource_uid" type="int" multiple>; <dtml-sqltest uid column="resource_uid" type="int" multiple>
<dtml-let measure_list="[]"> <dtml-let measure_list="[]">
<dtml-in getMeasureRowList prefix="loop"> <dtml-in getMeasureRowList prefix="loop">
...@@ -9,7 +9,7 @@ DELETE FROM `measure` WHERE ...@@ -9,7 +9,7 @@ DELETE FROM `measure` WHERE
<dtml-if measure_list> <dtml-if measure_list>
<dtml-var sql_delimiter> <dtml-var sql_delimiter>
REPLACE INTO `measure` INSERT INTO `measure`
VALUES VALUES
<dtml-in measure_list prefix="loop"> <dtml-in measure_list prefix="loop">
( (
......
DELETE FROM DELETE FROM
category category
WHERE WHERE
<dtml-in uid> <dtml-sqltest uid type="int" multiple>
uid=<dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>
</dtml-in> <dtml-var sql_delimiter>
;
<dtml-var "'\0'">
<dtml-let category_list="[]" getCategoryParentUidList="portal_categories.getCategoryParentUidList"> <dtml-let category_list="[]" getCategoryParentUidList="portal_categories.getCategoryParentUidList">
<dtml-in prefix="loop" expr="_.range(_.len(uid))"> <dtml-in prefix="loop" expr="_.range(_.len(uid))">
<dtml-if expr="getCategoryList[loop_item]"> <dtml-if expr="getCategoryList[loop_item]">
...@@ -15,7 +14,7 @@ WHERE ...@@ -15,7 +14,7 @@ WHERE
<dtml-call expr="category_list.append((uid[loop_item], uid_item[0], uid_item[1], uid_item[2]))"> <dtml-call expr="category_list.append((uid[loop_item], uid_item[0], uid_item[1], uid_item[2]))">
</dtml-in></dtml-if></dtml-let></dtml-if></dtml-in> </dtml-in></dtml-if></dtml-let></dtml-if></dtml-in>
<dtml-if expr="category_list"> <dtml-if expr="category_list">
REPLACE INTO category VALUES INSERT INTO category VALUES
<dtml-in prefix="loop" expr="category_list"> <dtml-in prefix="loop" expr="category_list">
(<dtml-sqlvar expr="loop_item[0]" type="int">, <dtml-sqlvar expr="loop_item[1]" type="int">, <dtml-sqlvar expr="loop_item[2]" type="int">, <dtml-sqlvar expr="loop_item[3]" type="int">)<dtml-if sequence-end><dtml-else>,</dtml-if> (<dtml-sqlvar expr="loop_item[0]" type="int">, <dtml-sqlvar expr="loop_item[1]" type="int">, <dtml-sqlvar expr="loop_item[2]" type="int">, <dtml-sqlvar expr="loop_item[3]" type="int">)<dtml-if sequence-end><dtml-else>,</dtml-if>
</dtml-in> </dtml-in>
......
DELETE FROM DELETE FROM
category category
WHERE WHERE
<dtml-in uid> <dtml-sqltest uid type="int" multiple>
uid=<dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>
</dtml-in> <dtml-var sql_delimiter>
;
<dtml-var "'\0'">
<dtml-let category_list="[]" getCategoryParentUidList="portal_categories.getCategoryParentUidList"> <dtml-let category_list="[]" getCategoryParentUidList="portal_categories.getCategoryParentUidList">
<dtml-in prefix="loop" expr="_.range(_.len(uid))"> <dtml-in prefix="loop" expr="_.range(_.len(uid))">
<dtml-if expr="getAcquiredCategoryList[loop_item]"> <dtml-if expr="getAcquiredCategoryList[loop_item]">
...@@ -15,7 +14,7 @@ WHERE ...@@ -15,7 +14,7 @@ WHERE
<dtml-call expr="category_list.append((uid[loop_item], uid_item[0], uid_item[1], uid_item[2]))"> <dtml-call expr="category_list.append((uid[loop_item], uid_item[0], uid_item[1], uid_item[2]))">
</dtml-in></dtml-if></dtml-let></dtml-if></dtml-in> </dtml-in></dtml-if></dtml-let></dtml-if></dtml-in>
<dtml-if expr="category_list"> <dtml-if expr="category_list">
REPLACE INTO category VALUES INSERT INTO category VALUES
<dtml-in prefix="loop" expr="category_list"> <dtml-in prefix="loop" expr="category_list">
(<dtml-sqlvar expr="loop_item[0]" type="int">, <dtml-sqlvar expr="loop_item[1]" type="int">, <dtml-sqlvar expr="loop_item[2]" type="int">, <dtml-sqlvar expr="loop_item[3]" type="int">)<dtml-if sequence-end><dtml-else>,</dtml-if> (<dtml-sqlvar expr="loop_item[0]" type="int">, <dtml-sqlvar expr="loop_item[1]" type="int">, <dtml-sqlvar expr="loop_item[2]" type="int">, <dtml-sqlvar expr="loop_item[3]" type="int">)<dtml-if sequence-end><dtml-else>,</dtml-if>
</dtml-in> </dtml-in>
......
DELETE FROM DELETE FROM
predicate_category predicate_category
WHERE WHERE
<dtml-in uid> <dtml-sqltest uid type="int" multiple>
uid=<dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>
</dtml-in>
;
<dtml-var "'\0'"> <dtml-var sql_delimiter>
<dtml-let predicate_list="[]"> <dtml-let predicate_list="[]">
<dtml-in prefix="loop" expr="_.range(_.len(uid))"> <dtml-in prefix="loop" expr="_.range(_.len(uid))">
...@@ -17,7 +14,7 @@ WHERE ...@@ -17,7 +14,7 @@ WHERE
</dtml-if> </dtml-if>
</dtml-in> </dtml-in>
<dtml-if expr="_.len(predicate_list) > 0"> <dtml-if expr="_.len(predicate_list) > 0">
REPLACE INTO predicate_category VALUES INSERT INTO predicate_category VALUES
<dtml-in prefix="loop" expr="predicate_list"> <dtml-in prefix="loop" expr="predicate_list">
<dtml-if sequence-start><dtml-else>,</dtml-if> <dtml-if sequence-start><dtml-else>,</dtml-if>
<dtml-if "predicate_property_dict[loop_item].has_key('membership_criterion_category_list')"> <dtml-if "predicate_property_dict[loop_item].has_key('membership_criterion_category_list')">
......
DELETE FROM
predicate
WHERE
<dtml-sqltest uid type="int" multiple>
<dtml-var sql_delimiter>
<dtml-let predicate_list="[]"> <dtml-let predicate_list="[]">
<dtml-in prefix="loop" expr="_.range(_.len(uid))"> <dtml-in prefix="loop" expr="_.range(_.len(uid))">
<dtml-if "isPredicate[loop_item]"> <dtml-if "isPredicate[loop_item]">
...@@ -7,7 +14,7 @@ ...@@ -7,7 +14,7 @@
</dtml-if> </dtml-if>
</dtml-in> </dtml-in>
<dtml-if expr="_.len(predicate_list) > 0"> <dtml-if expr="_.len(predicate_list) > 0">
REPLACE INTO predicate VALUES INSERT INTO predicate VALUES
<dtml-in prefix="loop" expr="predicate_list"> <dtml-in prefix="loop" expr="predicate_list">
<dtml-if sequence-start><dtml-else>,</dtml-if> <dtml-if sequence-start><dtml-else>,</dtml-if>
( (
......
...@@ -13,8 +13,7 @@ ...@@ -13,8 +13,7 @@
<dtml-if quantity_unit_conversion_dict> <dtml-if quantity_unit_conversion_dict>
DELETE FROM `quantity_unit_conversion` WHERE DELETE FROM `quantity_unit_conversion` WHERE
<dtml-sqltest "quantity_unit_conversion_dict.keys()" column="resource_uid" type="int" multiple>; <dtml-sqltest "quantity_unit_conversion_dict.keys()" column="resource_uid" type="int" multiple>
<dtml-var sql_delimiter> <dtml-var sql_delimiter>
...@@ -22,8 +21,7 @@ DELETE FROM `quantity_unit_conversion` WHERE ...@@ -22,8 +21,7 @@ DELETE FROM `quantity_unit_conversion` WHERE
<dtml-call "value_list.extend(loop_item.values())"> <dtml-call "value_list.extend(loop_item.values())">
</dtml-in> </dtml-in>
REPLACE INTO `quantity_unit_conversion` INSERT INTO `quantity_unit_conversion` VALUES
VALUES
<dtml-in "value_list" prefix="loop"> <dtml-in "value_list" prefix="loop">
( (
<dtml-sqlvar expr="loop_item['uid']" type="int" optional>, <dtml-sqlvar expr="loop_item['uid']" type="int" optional>,
......
DELETE FROM DELETE FROM
stock stock
WHERE WHERE
<dtml-in uid> <dtml-sqltest uid type="int" multiple>
uid=<dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>
</dtml-in> <dtml-var sql_delimiter>
;
<dtml-var "'\0'">
<dtml-let row_list="[]" uid_dict="{}"> <dtml-let row_list="[]" uid_dict="{}">
<dtml-in prefix="loop" expr="_.range(_.len(uid))"> <dtml-in prefix="loop" expr="_.range(_.len(uid))">
<dtml-if "not(isInventoryMovement[loop_item]) and isMovement[loop_item] and getResourceUid[loop_item]"> <dtml-if "not(isInventoryMovement[loop_item]) and isMovement[loop_item] and getResourceUid[loop_item]">
...@@ -74,7 +72,7 @@ WHERE ...@@ -74,7 +72,7 @@ WHERE
</dtml-in> </dtml-in>
<dtml-if "row_list"> <dtml-if "row_list">
REPLACE INTO INSERT INTO
stock stock
( (
`uid`, `uid`,
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
DELETE FROM `transformation` WHERE DELETE FROM `transformation` WHERE
<dtml-sqltest expr="outer_item['uid']" column="uid" type="int"> <dtml-sqltest expr="outer_item['uid']" column="uid" type="int">
AND AND
<dtml-sqltest expr="outer_item['variation_text']" column="variation_text" type="string">; <dtml-sqltest expr="outer_item['variation_text']" column="variation_text" type="string">
<dtml-var sql_delimiter> <dtml-var sql_delimiter>
<dtml-call "row_list.extend(outer_item['row_dict_list'])"> <dtml-call "row_list.extend(outer_item['row_dict_list'])">
</dtml-in> </dtml-in>
......
...@@ -4,9 +4,9 @@ VALUES ...@@ -4,9 +4,9 @@ VALUES
<dtml-in "_.range(count - 1)"> <dtml-in "_.range(count - 1)">
( <dtml-sqlvar instance_id type="string"> , 'reserved' ) , ( <dtml-sqlvar instance_id type="string"> , 'reserved' ) ,
</dtml-in> </dtml-in>
( <dtml-sqlvar instance_id type="string"> , 'reserved' ); ( <dtml-sqlvar instance_id type="string"> , 'reserved' )
<dtml-var "'\0'"> <dtml-var sql_delimiter>
SELECT SELECT
uid uid
......
...@@ -616,6 +616,44 @@ class TestPredicates(TestPredicateMixIn): ...@@ -616,6 +616,44 @@ class TestPredicates(TestPredicateMixIn):
self.assertFalse(getattr(predicate, '_identity_criterion', None) is None) self.assertFalse(getattr(predicate, '_identity_criterion', None) is None)
self.assertFalse(getattr(predicate, '_range_criterion', None) is None) self.assertFalse(getattr(predicate, '_range_criterion', None) is None)
def test_predicateIndexation(self):
predicate = self.createPredicate(
membership_criterion_base_category_list = ['region'],
membership_criterion_category_list = [REGION_FRANCE_PATH]
)
# Our test document will only be a predicate if title is different
# from 'never applies'
createZODBPythonScript(
self.portal.portal_skins.custom,
'Predicate_asPredicate',
'',
"""return None if context.getTitle() == 'never applies' else context""")
self.tic()
self.assertEqual(
[predicate],
[brain.getObject() for brain in self.portal.portal_catalog(
**{'predicate.uid': predicate.getUid()})])
self.assertEqual(
[predicate],
[brain.getObject() for brain in self.portal.portal_catalog(
**{'predicate_category.uid': predicate.getUid()})])
predicate.setTitle("never applies")
# this predicate is no longer a predicate, so it no longer exist in predicate tables
self.tic()
self.assertEqual(
[],
[brain.getObject() for brain in self.portal.portal_catalog(
**{'predicate.uid': predicate.getUid()})])
self.assertEqual(
[],
[brain.getObject() for brain in self.portal.portal_catalog(
**{'predicate_category.uid': predicate.getUid()})])
# TODO : # TODO :
# multi membership category # multi membership category
# asPredicate scripts # asPredicate scripts
......
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