odoo/odoo#159667
Created by SM Customer, NoƩ Antoine (nan)
Blocked
- Merge method
- Review
-
CI
- legal/cla: Contributor License Agreement check
- ci/runbot: Odoo Test Suite
- ci/upgrade_enterprise: Test upgrades for enterprise master
- ci/style: Optional style check. Ignore it only if strictly necessary.
- ci/security: Required security check. Can only be ignored by security team.
- label
- odoo-dev:master-crm-unpls_the_pls-nan
- head
- dafc12c969dae1944d9b896426682df9038d8877
| odoo/odoo | |
|---|---|
| master | #159667 missing r+ |
[IMP] crm: defer live pls updates to CRON
BEFORE THE MAIN COMMIT
When a lead is won or lost, we increment on the spot the
table of frequencies according to the lead values. This will
lead to correctly computed probabilities when another lead is
updated, aknowledging the recently won / lost lead. This is
generating quite a few operations each time, and writes to the
frequency table.
ISSUE
The issue is that this generates a lot of operations, and in a db
with a lot of traffic we can end up with concurrent updates on the
frequency table as different leads with the same team (even more
for leads with similar values for PLS fields) will update the same
entries of the frequency table.
AFTER THE MAIN COMMIT
We do not do frequency updates on the spot. This means that the few
first leads may have incorrect probability value, but once the table
is populated, the difference will be less and less visible.
Instead, when a lead is won or lost, we create a new record in a
small table tracking status update of leads. The table is only 4
booleans (from_won, from_lost, to_won, to_lost) and the lead_id.
This means that we cannot end up with concurrent updates. Instead,
we defer those to a CRON running quite frequently. It will take the
full new table of 'pending updates', will process the frequency updates
according to the lead status evolution and values, and will end up
creating new / updating each existing frequency only once. This reduces
number of requests and prevents concurrent updates. The tradoff is a
bit of precision before the next run of the CRON.
OTHER CHANGES
The PLS code is a bit changed and methods renamed. Now, we compute
deltas for a given frequency entry according to all updates, so we
may end up with -3 won_count and +10 lost_count for example, on a
given (team, field, value) entry. This way we update a single time
the frequency.
A few variables are renamed to be more accurate (a frequency is not
the same as the value of a lead for a PLS field). Also, the score
initialization is a bit modified to make the code more readable.
TESTS
We must now process pending updates before asserting new probability
values in the existing tests.
OTHER COMMITS
- Some tests are reworked, as they did not work as expected. Some
ghost behaviors are removed, and made explicit. - A tour is fixed and reintroduced
- The PLS code is cleaned and docstrings are improved and sometimes
updated (as they were out of date), as the implementation (and its
hypotheses) is sometimes too implicit and a new reader may be quite
confused.