[IMP] account_invoice_section_sale_order: speed up #2024
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Forward port of #2022
On large invoices, at least on 17.0, rewriting the sequence of the invoice lines is very slow, as it triggers a flush to disk for each line (this is even worse when the database is lot running on the same server).
This commit implements a different method for inserting the sections in the invoice lines: we precreate the lines with spaced out sequence numbers, and then we can add the sections between the existing lines, which is much faster.
Test on 17.0: 47 sale orders for 2 customers, generation of 2 invoices with 1200 and 900 lines respectively
Without patch: 9678 SQL queries, 6.868s in SQL 461.969s in Python, total time: 469s
With patch: 5660 SQL queries 1.934 in SQL, 24.167s in Python, total time 26s