Skip to content
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

Open
wants to merge 1 commit into
base: 17.0
Choose a base branch
from

Conversation

anikeenko-viktor
Copy link

Speed up _apply_inventory by writing all new moves at once to inventory. Almost 10 times faster for my case on average.

Before:
image

After (there's no bunch of writes anymore):
image

@anikeenko-viktor anikeenko-viktor force-pushed the 17.0-stock_inventory-apply-inventory-perf branch from 21f20d9 to f31897a Compare January 15, 2025 13:01
):
new_moves = self.env["stock.move.line"]
for quant in quant_list:
moves = record_moves.search(
Copy link
Contributor

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]
Copy link
Contributor

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:

Suggested change
move = moves[len(moves) - 1]
move = moves[-1]

"reference": reference,
}
)
quant.to_do = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"]
Copy link
Contributor

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:

Suggested change
new_moves = self.env["stock.move.line"]
new_moves = self.env["stock.move.line"].browse()

@rousseldenis rousseldenis added this to the 17.0 milestone Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants