searchAndActivate: rework 'activity_count' parameter
- It's not deprecated anymore. - When activities are grouped at CMFActivity level, it specifies a number of activities that are generated at a time instead of a number of activity groups. - The special None value means no limit.
-
Owner
About no-limit behaviour: what is then the added value of calling
searchAndActivate
?In other word, why not then directly doing:
for row in portal_catalog(...): row.activate(...).doFoo(...)
This allows getting rid of
searchAndActivate
's expensive sort on uid, so it should get better performance, and this code seems simple enough that it should not require wrapping it in a function.The only benefit I can think of when calling into code which already wraps
searchAndActive
and sometimes runs fast queries and/or with large result sets, and sometimes runs slow queries with small result sets. Which seems rather niche. -
Owner
Oops how I missed the useless sort ? Anyway, at least in my case, it didn't slow down:
- with sort: Query_time: 10590.548910 Lock_time: 0.000064 Rows_sent: 97636 Rows_examined: 2383154
- without: Query_time: 10622.009253 Lock_time: 0.000099 Rows_sent: 97635 Rows_examined: 2381524
BTW, the query is for a migration script that will be only run twice (1 to simulate & 1 for real; it's not worth optimizing):
self.portal_catalog._searchAndActivate(script_id, method_kw=dict(...), activate_kw=dict(active_process=active_process, tag=script_id, priority=11), portal_type='Simulation Movement', strict_resource_uid=[a list of 6 service uids], group_by='parent_uid')
The explain by MariaDB 10.1:
+------+-------------+----------------------------------------+--------+---------------------+------------+---------+-------------------------------------------------+---------+-----------------------------------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +------+-------------+----------------------------------------+--------+---------------------+------------+---------+-------------------------------------------------+---------+-----------------------------------------------------------+ | 1 | SIMPLE | related_strict_resource_uid_1_category | range | PRIMARY,Membership | Membership | 16 | NULL | 2350894 | Using where; Using index; Using temporary; Using filesort | | 1 | SIMPLE | catalog | eq_ref | PRIMARY,Portal Type | PRIMARY | 8 | erp5.related_strict_resource_uid_1_category.uid | 1 | Using where | +------+-------------+----------------------------------------+--------+---------------------+------------+---------+-------------------------------------------------+---------+-----------------------------------------------------------+
About no-limit behaviour: what is then the added value of calling
searchAndActivate
?Indeed, not much. In addition to the reason you gave:
- it sets a default grouping
- it's not trivial anymore when select_method_id is used
- in my use case, the code was written from the beginning with _searchAndActivate (and no perf issue on a smaller instance) and I didn't want to rewrite all the above code
-
Owner
at least in my case, it didn't slow down:
Oh, indeed, when and there is no limit, the sort happens last, and with such small(-ish) result set the sort should be fast.
In addition to the reason you gave:
All good points, thanks. So this change looks good to me, and thank you for the follow-up change disabling the sort.