Skip to content

Commit 07e26e3

Browse files
committed
[PERF] account: optimize migration performance by pre-creating column
and bulk transferring invoice_date Pre-create the target column to avoid triggering compute() during update, and perform a direct bulk data transfer from account_move to account_move_line. This avoids ORM overhead, reduces heap rewrites, and prevents unnecessary recomputation on 15M move lines. Performance result: - Previous approach: ~2 hours - Optimized approach: ~15 minutes (~8x faster)
1 parent 6a86957 commit 07e26e3

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

openupgrade_scripts/scripts/account/17.0.1.2/pre-migration.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,26 @@ def _pre_create_early_pay_discount_computation(env):
204204
)
205205

206206

207+
def _pre_account_move_line_invoice_date_computation(env):
208+
"""Avoid triggering the computed method"""
209+
openupgrade.logged_query(
210+
env.cr,
211+
"""
212+
ALTER TABLE account_move_line
213+
ADD COLUMN IF NOT EXISTS invoice_date DATE;
214+
""",
215+
)
216+
openupgrade.logged_query(
217+
env.cr,
218+
"""
219+
UPDATE account_move_line aml
220+
SET invoice_date = am.invoice_date
221+
FROM account_move am
222+
WHERE am.invoice_date IS NOT NULL AND aml.move_id = am.id;
223+
""",
224+
)
225+
226+
207227
def _decouple_obsolete_tables(env):
208228
"""
209229
Remove all foreign keys held by and pointed to template tables
@@ -289,6 +309,7 @@ def migrate(env, version):
289309
_account_report_update_figure_type(env)
290310
_account_tax_repartition_line_merge_repartition_lines_m2o(env)
291311
_pre_create_early_pay_discount_computation(env)
312+
_pre_account_move_line_invoice_date_computation(env)
292313
_decouple_obsolete_tables(env)
293314
_pre_create_account_report_active(env)
294315
_remove_obsolete_constraints(env)

openupgrade_scripts/scripts/account/17.0.1.2/upgrade_analysis_work.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ account / account.move.line / display_type (selection) : select
167167
# NOTHING TO DO: new feature "Discount allocation" https://github.com/odoo/odoo/pull/133286
168168

169169
account / account.move.line / invoice_date (date) : NEW isrelated: related, stored
170-
# NOTHING TO DO: ORM resolves by SQL this filling being a direct related field with 1 level depth.
170+
# DONE: pre-migration: Pre-create the column for avoiding triggering the compute and transfer data from account moves to all the account move lines.
171171

172172
account / account.move.line / tax_audit (char) : DEL
173173
# NOTHING TO DO: deprecated

0 commit comments

Comments
 (0)