Stock validation caches only the quants it reads
Validating moves no longer loads quants of other packages or owners. On a database with 700k quants at a customer location, that was most of the table.
Validating moves no longer loads quants of other packages or owners. On a database with 700k quants at a customer location, that was most of the table.
| Branch | Pull request | Commit |
|---|---|---|
| 18.0 | odoo/odoo#291143 ↗ | e0d3d4ea57 ↗ |
| 19.0 | odoo/odoo#293377 ↗ | f8d69ee0af ↗ |
| 20.0 | odoo/odoo#294724 ↗ | 61716e88e1 ↗ |
[PERF] stock: cache only the quants the validation loop can read
'_action_done' on 'stock.move.line' builds a quants cache for the products
of the lines at their source and destination locations, with 'child_of' on
those locations and one filter on the lines' lots. The loop that follows
gathers in strict mode, matching lot, package and owner exactly, so quants
under any other package or owner load into the cache and are never read.
At a customer location this is most of the table: a returnable packaging
reference shipped in its own package leaves one quant per shipment, and
nothing merges or consumes them. On a database with 709,769 such quants
under Partner Locations/Customers, measured on an Odoo.sh staging copy:
- delivery of 1708 lines, 4 products, 862 packages, 3 lots: the cache
domain matches 761,950 quants; '_read_group' with 'id:recordset' on them
gets the process killed (SIGKILL, exit 137) before 'button_validate'
can raise anything. With the filter below the same domain matches
1,715 quants and the cache builds in 0.019 s.
- delivery of 992 lines, 3 products, 991 packages, 1 lot: 47,212 quants,
0.438 s and 44 MB of resident memory for the cache, against 19 quants
in 0.025 s and no measurable memory.
Filter the cache on the lines' packages ('package_id' and
'result_package_id') and owners the way it is filtered on lots. The strict
gathers of the loop match nothing else, so they read the same quants as
before.
'_free_reservation' runs '_action_assign' on other move lines, whose
packages and lots are not in the cache. Run it without the cache, as 18.0
does since cf9b3f854fe4e186f7ad6465d455cbbb9934df58.