Skip to content

[16.0][IMP] account_invoice_triple_discount: Improve migration performance#2279

Draft
lmignon wants to merge 1 commit intoOCA:16.0from
acsone:16.0-account_triple_discount-perf-lmi
Draft

[16.0][IMP] account_invoice_triple_discount: Improve migration performance#2279
lmignon wants to merge 1 commit intoOCA:16.0from
acsone:16.0-account_triple_discount-perf-lmi

Conversation

@lmignon
Copy link
Contributor

@lmignon lmignon commented Feb 25, 2026

Use the upgrade util library lib from Odoo if available to migrate data to improve performances.

It allows accounting line data to be updated in parallel (10 threads) in ranges of 10,000 rows. This significantly reduces the time required for migration. On a database with more than 12,000,000 account.move.line entries, before the change, the process was killed after 3 hours because it was taking too long. After the change, the update was completed in 12 minutes.

Use the upgrade util library lib from Odoo if available to migrate data to improve performances.

It allows accounting line data to be updated in parallel (10 threads) in ranges of 10,000 rows. This significantly reduces the time required for migration. On a database with more than 12,000,000 account.move.line entries, before the change, the process was killed after 3 hours because it was taking too long. After the change, the update was completed in 12 minutes.
@lmignon
Copy link
Contributor Author

lmignon commented Feb 25, 2026

@lmignon lmignon marked this pull request as draft February 25, 2026 10:23
@lmignon
Copy link
Contributor Author

lmignon commented Feb 25, 2026

I convert it to draft the time to verify the data in my migrated database...

Copy link
Member

@hildickethan hildickethan left a comment

Choose a reason for hiding this comment

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

first time seeing odoo.upgrade, seems like it was created in 2023, does this replace openupgrade for migration scripts? the parallel features at least look powerful and it seems like it has most openupgrade features at a glance

discount = 100 * (
1 - (
(100 - COALESCE(discount1, 0.0)) / 100
(100 - COALESCE(discount, 0.0)) / 100
Copy link
Member

Choose a reason for hiding this comment

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

wouldnt this add discount2 and discount3 to discount again?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

when the request is executed, discount1 is not yet initialized and discount on the right side of the operator contains the original value into the row...

Copy link
Member

Choose a reason for hiding this comment

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

ah I see now

@lmignon
Copy link
Contributor Author

lmignon commented Feb 25, 2026

first time seeing odoo.upgrade, seems like it was created in 2023, does this replace openupgrade for migration scripts? the parallel features at least look powerful and it seems like it has most openupgrade features at a glance

This is the library used internally at Odoo for their migration scripts. It contains a lot of methods equivalent to those offered by OpenUpgrade-Utils. I now tend to prefer using it to OpenUpgrade-Utils because this library offers more advanced and powerful features. However, we can never be grateful enough for what OpenUpgrade-Utils has offered the community for so many years. The advantage of OpenUpgrade-Utils is that the community still controls its life cycle, which is not the case with the Odoo library....

Copy link
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

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

Maybe we can replicate that parallel query in openupgradelib in our OCA way...

@lmignon
Copy link
Contributor Author

lmignon commented Feb 27, 2026

Maybe we can replicate that parallel query in openupgradelib in our OCA way...

@pedrobaeza IMHO it's not a good idea. The odoo library is well maintained, heavily used, tested and improved by the Odoo team with performance and usability in mind. For example take a look to the commit message of one of the last change and you will see the complexity of the problems taken into account odoo/upgrade-util@cef1907.

=> We could maybe switch to the odoo upgrade lib for our migration script 🤔

However, I didn't want to open this debate or take sides for one lib or another in the context of this PR, just highlight an alternative while remaining compatible with the user's final choice. But it's definitely a topic that deserves to be discussed in the openupgrade group because the performance gains are huge and the tools offered cover all the cases encountered in migrations.

@pedrobaeza
Copy link
Member

Yeah, I see it's complex... but if we want to improve the performance in OU in general, we should think about it. Maybe including calls to these utils in some places. Something to think in general. Opened OCA/OpenUpgrade#5543.

Comment on lines -62 to +90
@openupgrade.migrate()
def migrate(env, version):
def migrate(cr, version):
env = Environment(cr, SUPERUSER_ID, {})
Copy link
Contributor

@legalsylvain legalsylvain Feb 27, 2026

Choose a reason for hiding this comment

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

Why this change ?

I think we could simplify the script.
-> Assuming that openupgrade exists. it's a regular OCA tools, used in many migrations scripts.
-> just implement USE_ODOOUPGRADE.
-> if openupgrade and odoopgrade exists, the script should use odooupgrade.

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.

4 participants