[16][FIX] stock_move_propagate_first_move #2163
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add index for first_move_id to improve performance
Without indexing first_move_id field, when trying to execute write method on a stock move, for example when we confirm a sale order. The query lasts for at least more than 7 seconds.
This slows down the system and can even cause PostgreSQL blocks.
As we can see in this profiler, the query:
sql('SELECT "stock_move".id FROM "stock_move" WHERE ("stock_move"."first_move_id" in %s) ORDER BY "stock_move"."id" ') (SELECT "stock_move".id FROM "stock_move" WHERE ("stock_move"."first_move_id" in (25199374)) ORDER BY "stock_move"."id" )
The query is consuming more than 70% of the order confirmation time, when making a return.
Whereas if we index the field first_move_id, the query lasts less than a second and all the process is finished in only 1 second