Thursday, July 6, 2023
1 change · master
Enhancements to existing features
Time-off requests in Belgian payroll now update related payroll benefits much faster on large databases. This reduces waiting time for HR users when posting time off, improving day-to-day responsiveness without changing payroll behavior.
Original PR description
## Description Taking a time-off in the Time Off application is taking around 7s on a large database. ## Analysis The bottleneck is `_compute_work_entry_dependent_benefits`, especially the query on…
## Description Taking a time-off in the Time Off application is taking around 7s on a large database. ## Analysis The bottleneck is `_compute_work_entry_dependent_benefits`, especially the query on the report `l10n_be.work.entry.daily.benefit. report`. It's making 2 `CROSS JOIN LATERAL`, making an expensive cross product, and filtering afterward based on conditions, that could have been checked during the `JOIN`s, before doing any `CROSS JOIN`. This reduces the total rows that Postgres is manipulating during the query. Moving the conditions earlier in the chain of joins, allows Postgres to make earlier filtering before doing any `CROSS JOIN`. Another issue is the ordering. When searching based a set of employees and a date range, we order based on the default order of the report, but it's never used afterward. We use a `dictfetchall()` so order is irrelevant. Removing the ordering, allows us to ditch the `id` in the `SELECT` of the report, which is an expensive window function doing ordering on potentially many rows. ## Results Posting a time-off passes from 11.13 secs to 16 ms --- task-3387393