[FW][FIX] mrp: installation on very large inventories

[FIX] mrp: installation on very large inventories

Before this commit, installation of MRP in a database with 4.8M stock.move + 4.8M stock.move.line was not possible at all.
The process lasted for a very long time (>90 min in our tests) then eventually failed after using the whole RAM of your server.

This commit allows installing MRP in databases with large stock.move /stock.move.line tables by bootstrapping the slow parts in SQL.

(A more general fix regarding the time complexity of some parts of the prefetching algorithm is coming later in 13.0-init-computed-fields-rco)

-----

[FIX] mrp: more Voodoo magic

It appears that if you update a record more than once in the same
PostgreSQL transaction, PostgreSQL is going to re-check all the
constraints on the table.

** THIS IS THE PART WHERE THE BLACK MAGIC HAPPENS **

We combine the setting of the default value of stock.move.unit_factor in
the same UPDATE query to avoid the constraint re-check; it saves
approximately 60% of the SQL running time in my case.

** ... AND NOW YOU CAN SAY: WHAT THE F...?! **

Thanks to @rco-odoo for the tip; he knows it from the wise @nseinlet.

-----

opw-[2281585](https://www.odoo.com/web?debug=1#id=2281585&action=3531&model=project.task&view_type=form&cids=&menu_id=4720)

closes odoo/odoo#57946

Forward-port-of: odoo/odoo#57850
Signed-off-by: Richard Mathot (rim) <rim@openerp.com>
This commit is contained in:
Odoo's Mergebot
2020-09-23 17:42:03 +02:00
committed by GitHub
2 changed files with 11 additions and 0 deletions
+10
View File
@@ -8,6 +8,16 @@ from . import controller
from odoo import api, SUPERUSER_ID
def _pre_init_mrp(cr):
""" Allow installing MRP in databases with large stock.move table (>1M records)
- Creating the computed+stored field stock_move.is_done is terribly slow with the ORM and
leads to "Out of Memory" crashes
"""
cr.execute("""ALTER TABLE "stock_move" ADD COLUMN "is_done" bool;""")
cr.execute("""UPDATE stock_move
SET is_done=COALESCE(state in ('done', 'cancel'), FALSE);""")
def _create_warehouse_data(cr, registry):
""" This hook is used to add a default manufacture_pull_id, manufacture
picking_type on every warehouse. It is necessary if the mrp module is
+1
View File
@@ -52,6 +52,7 @@
],
'test': [],
'application': True,
'pre_init_hook': '_pre_init_mrp',
'post_init_hook': '_create_warehouse_data',
'uninstall_hook': 'uninstall_hook',
}