Skip to content

[IMP] account_invoice_section_sale_order: speed up #2024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 18.0
Choose a base branch
from

Conversation

gurneyalex
Copy link
Member

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

return values
# update the sequence of the invoice lines, add some space between lines so that
# we can insert the sections afterwards.
# we use a mutable in the context to be able to update it and have the updated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but why a list? It's because of frozendict?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move this comment to where you inject it ;)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Forward port of OCA#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: 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
@gurneyalex gurneyalex force-pushed the 18.0-imp-account_invoice_section_sale_order branch from 66707e5 to 8a24b01 Compare June 10, 2025 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants