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
item
WHERE
<dtml-in uid>
uid=<dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>
</dtml-in>
;
<dtml-sqltest uid type="int" multiple>
<dtml-var "'\0'">
<dtml-var sql_delimiter>
<dtml-let movement_list="[]" uid_dict="{}">
<dtml-in prefix="loop" expr="_.range(_.len(uid))">
......@@ -16,7 +13,7 @@ WHERE
</dtml-if>
</dtml-in>
<dtml-if expr="_.len(movement_list) > 0">
REPLACE INTO
INSERT INTO
item
VALUES
<dtml-in prefix="loop" expr="movement_list">
......
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-in getMeasureRowList prefix="loop">
......@@ -9,7 +9,7 @@ DELETE FROM `measure` WHERE
<dtml-if measure_list>
<dtml-var sql_delimiter>
REPLACE INTO `measure`
INSERT INTO `measure`
VALUES
<dtml-in measure_list prefix="loop">
(
......
DELETE FROM
category
WHERE
<dtml-in uid>
uid=<dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>
</dtml-in>
;
<dtml-var "'\0'">
<dtml-sqltest uid type="int" multiple>
<dtml-var sql_delimiter>
<dtml-let category_list="[]" getCategoryParentUidList="portal_categories.getCategoryParentUidList">
<dtml-in prefix="loop" expr="_.range(_.len(uid))">
<dtml-if expr="getCategoryList[loop_item]">
......@@ -15,7 +14,7 @@ WHERE
<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-if expr="category_list">
REPLACE INTO category VALUES
INSERT INTO category VALUES
<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-in>
......
DELETE FROM
category
WHERE
<dtml-in uid>
uid=<dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>
</dtml-in>
;
<dtml-var "'\0'">
<dtml-sqltest uid type="int" multiple>
<dtml-var sql_delimiter>
<dtml-let category_list="[]" getCategoryParentUidList="portal_categories.getCategoryParentUidList">
<dtml-in prefix="loop" expr="_.range(_.len(uid))">
<dtml-if expr="getAcquiredCategoryList[loop_item]">
......@@ -15,7 +14,7 @@ WHERE
<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-if expr="category_list">
REPLACE INTO category VALUES
INSERT INTO category VALUES
<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-in>
......
DELETE FROM
predicate_category
WHERE
<dtml-in uid>
uid=<dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>
</dtml-in>
;
<dtml-sqltest uid type="int" multiple>
<dtml-var "'\0'">
<dtml-var sql_delimiter>
<dtml-let predicate_list="[]">
<dtml-in prefix="loop" expr="_.range(_.len(uid))">
......@@ -17,7 +14,7 @@ WHERE
</dtml-if>
</dtml-in>
<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-if sequence-start><dtml-else>,</dtml-if>
<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-in prefix="loop" expr="_.range(_.len(uid))">
<dtml-if "isPredicate[loop_item]">
......@@ -7,7 +14,7 @@
</dtml-if>
</dtml-in>
<dtml-if expr="_.len(predicate_list) > 0">
REPLACE INTO predicate VALUES
INSERT INTO predicate VALUES
<dtml-in prefix="loop" expr="predicate_list">
<dtml-if sequence-start><dtml-else>,</dtml-if>
(
......
......@@ -13,8 +13,7 @@
<dtml-if quantity_unit_conversion_dict>
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>
......@@ -22,8 +21,7 @@ DELETE FROM `quantity_unit_conversion` WHERE
<dtml-call "value_list.extend(loop_item.values())">
</dtml-in>
REPLACE INTO `quantity_unit_conversion`
VALUES
INSERT INTO `quantity_unit_conversion` VALUES
<dtml-in "value_list" prefix="loop">
(
<dtml-sqlvar expr="loop_item['uid']" type="int" optional>,
......
DELETE FROM
stock
WHERE
<dtml-in uid>
uid=<dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>
</dtml-in>
;
<dtml-sqltest uid type="int" multiple>
<dtml-var sql_delimiter>
<dtml-var "'\0'">
<dtml-let row_list="[]" uid_dict="{}">
<dtml-in prefix="loop" expr="_.range(_.len(uid))">
<dtml-if "not(isInventoryMovement[loop_item]) and isMovement[loop_item] and getResourceUid[loop_item]">
......@@ -74,7 +72,7 @@ WHERE
</dtml-in>
<dtml-if "row_list">
REPLACE INTO
INSERT INTO
stock
(
`uid`,
......
......@@ -3,7 +3,7 @@
DELETE FROM `transformation` WHERE
<dtml-sqltest expr="outer_item['uid']" column="uid" type="int">
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-call "row_list.extend(outer_item['row_dict_list'])">
</dtml-in>
......
......@@ -4,9 +4,9 @@ VALUES
<dtml-in "_.range(count - 1)">
( <dtml-sqlvar instance_id type="string"> , 'reserved' ) ,
</dtml-in>
( <dtml-sqlvar instance_id type="string"> , 'reserved' );
( <dtml-sqlvar instance_id type="string"> , 'reserved' )
<dtml-var "'\0'">
<dtml-var sql_delimiter>
SELECT
uid
......
......@@ -616,6 +616,44 @@ class TestPredicates(TestPredicateMixIn):
self.assertFalse(getattr(predicate, '_identity_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 :
# multi membership category
# 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