Monday, November 29, 2021
2 changes · master
Resolved issues and error corrections
Improves performance when creating very large batches of records that include certain calculated fields. This reduces long processing times for bulk imports or automated data creation, making large operations complete much faster.
Original PR description
Issue: ------ The `create` method (models.py) doesn't scale correctly (with huge number of values) **when compute store no-readonly field(s) are in values** (at most one). It is due to the method…
Issue: ------ The `create` method (models.py) doesn't scale correctly (with huge number of values) **when compute store no-readonly field(s) are in values** (at most one). It is due to the method `protecting` (api.py) which has a bad complexity in the `create` situation (list of (field, records) pairs as argument): O(r²) with `r` = number of record containing the protected field: List of `len(r)` send to `protecting`, loop of this list (`r` factor), loop on fields (constant factor), create a new frozen set with the previous one (`r` factor). Fix: ---- Decrease the complexity to O(r) by creating a map of set of ids by protected field which allows avoiding recreating a new frozenset for each record (update with tuple of one inside => O(1)). Performance gain: ---------- For a very simple model with only one compute store no-readonly field, and all `create` `values` contains this field. ``` +--------------+---------------+---------------+---------------+----------------+ | Batch -> | 1000 | 10000 | 30000 | 80000 | +--------------+---------------+---------------+---------------+----------------+ | Before (sec) | 0.083 ± 0.006 | 1.433 ± 0.091 | 8.764 ± 0.609 | 94.428 ± 3.021 | | After (sec) | 0.069 ± 0.003 | 0.706 ± 0.006 | 2.188 ± 0.076 | 5.875 ± 0.104 | +--------------+---------------+---------------+---------------+----------------+ ```
The manual "Run Now" action for scheduled jobs now behaves the same way as automatic execution. This prevents user language settings from changing results unexpectedly, making logs and scheduled job behavior more consistent.
Original PR description
Change the lang of your user, translate the name of some records (e.g. translate the "Customizable Desk" product to "Bureau personnalisable") and create a cron that simply log the name of that record. Schedule the cron to be automatically executed, check the created log entry (`setting > technical > logging`) it is the default english name. Go back to the cron, click "run now" contextual button, check the created log entry: it is the translated name. When they are automatically executed by the cron worker, crons run with a minimal context without lang. When the user clicks on the "run now" button his context was wrongly used while executing the code. Closes #45388