-
-
Notifications
You must be signed in to change notification settings - Fork 733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[17.0][PERF] stock_inventory: reduce amount of write operations #2236
base: 17.0
Are you sure you want to change the base?
[17.0][PERF] stock_inventory: reduce amount of write operations #2236
Conversation
21f20d9
to
f31897a
Compare
): | ||
new_moves = self.env["stock.move.line"] | ||
for quant in quant_list: | ||
moves = record_moves.search( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, this should not be done in the loop.
Do it before (even before the groupby(). Then use the filter in the loop. That can increase performances massively
) | ||
if len(moves) == 0: | ||
raise ValueError(_("No move lines have been created")) | ||
move = moves[len(moves) - 1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is more correct to get the last one:
move = moves[len(moves) - 1] | |
move = moves[-1] |
"reference": reference, | ||
} | ||
) | ||
quant.to_do = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quant.to_do = False | |
quant.update({ | |
"to_do": False, | |
"current_inventory": False | |
}) |
for adjustment, quant_list in groupby( | ||
self, key=lambda x: x.current_inventory_id | ||
): | ||
new_moves = self.env["stock.move.line"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more correct syntaxically:
new_moves = self.env["stock.move.line"] | |
new_moves = self.env["stock.move.line"].browse() |
Speed up
_apply_inventory
by writing all new moves at once to inventory. Almost 10 times faster for my case on average.Before:
![image](https://private-user-images.githubusercontent.com/11441156/403422507-97c99bfd-2e28-4cfc-bb40-72ba1ed39e36.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzNTk1NTEsIm5iZiI6MTczOTM1OTI1MSwicGF0aCI6Ii8xMTQ0MTE1Ni80MDM0MjI1MDctOTdjOTliZmQtMmUyOC00Y2ZjLWJiNDAtNzJiYTFlZDM5ZTM2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEyVDExMjA1MVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTY5MmFjZDBhMGZkNWM3MWQ0ODU2YjhjM2FkN2IwYzc2ZjAyMGU5ODE5YTIzYTE0MjMzNjc0NDc4ODQyYWE0NjAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.Azd5LTyu-5M-1emzffQ1NasHmuJbzRdv54BNlBlYAeI)
After (there's no bunch of writes anymore):
![image](https://private-user-images.githubusercontent.com/11441156/403422593-f11ac1aa-b7ac-41ea-8a80-fa4f4b8ef423.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzNTk1NTEsIm5iZiI6MTczOTM1OTI1MSwicGF0aCI6Ii8xMTQ0MTE1Ni80MDM0MjI1OTMtZjExYWMxYWEtYjdhYy00MWVhLThhODAtZmE0ZjRiOGVmNDIzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEyVDExMjA1MVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTE5N2FhOTljNjA5MmViYWUzZjlmNTE3NTZhMjk5NWMxMDQ2NTFmNzEzYThkYjdjN2UxNzk4ZTlmMmIzMGYxNzAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.teeXmM-mV6YyJ2fcCSNUfPDMSMv3PMdfJX-5s_wpUto)