Optimization Product products_by_location - slow calculation to faster -
Since update v3.4 -> v3.8, there are optimization some process.
In case "Product.products_by_location" to know each product and quantity - location, continues to be slow.
Example a warehouse:
1- One warehouse
2- 7673 locations actives
3. +5400 moves each day (supplier/customer)
Tests
-----
We have a custome method call Product.products_by_location. Here there are 2 examples and time execution.
In those test, only calculate a product (increase times more products).
1. Call with Product.products_by_location:
6922119 function calls (6274604 primitive calls) in 76.788 seconds
Before call Product.products_by_location: 2016-03-31 15:24:44.028261
After call Product.products_by_location: 2016-03-31 15:25:58.573997
To calculate products_by_location spend more than 1 minute.
Hard methods to calculate are:
1 0.035 0.035 74.470 74.470 move.py:1142(compute_quantities)
1 0.000 0.000 74.544 74.544 product.py:135(products_by_location)
23 69.560 3.024 69.561 3.024 {method 'execute' of 'psycopg2.extensions.cursor' objects}
2. Replace Product.products_by_location to a custom SQL and to get stock locations
434269 function calls (433447 primitive calls) in 0.875 seconds
In those 2 examples, products_by_location is very slow than direct a SQL.
How to optimitze this method? Feedback?