Skip to content

[16.0][IMP] shopfloor: improve performance of generic_find#1174

Open
nicolas-delbovier-acsone wants to merge 3 commits into
OCA:16.0from
acsone:16.0-imp-shopfloor_reception-find-avoid-useless-searches
Open

[16.0][IMP] shopfloor: improve performance of generic_find#1174
nicolas-delbovier-acsone wants to merge 3 commits into
OCA:16.0from
acsone:16.0-imp-shopfloor_reception-find-avoid-useless-searches

Conversation

@nicolas-delbovier-acsone
Copy link
Copy Markdown

@nicolas-delbovier-acsone nicolas-delbovier-acsone commented Jun 3, 2026

Problem

The generic_find method in shopfloor suffered from two performance bottlenecks during barcode scanning:

  1. Redundant Handler Scans: Even when the parser successfully identified a highly specific barcode type (e.g., a GS1 'lot'), the loop structure would blindly execute database queries across all other active handlers (e.g., 'package', 'product', 'location').
  2. Suboptimal Order of Execution: Because the parser sequence injects an "unknown" result type (representing the raw string fallback) at the beginning of the results collection, the method consistently evaluated this generic fallback first (and thus tested all possible types instead of only one).

Also includes

  • Found a file not named properly in shopfloor_gs1 -> renamed to not be misleading in the future / improve code navigation

When the parser was able to detect some type (e.g. "lot") this is stupid to test all the others that we know will not work ("packaging", "product", ...)
In `generic_find`, the list of parsed results always starts with an
"unknown" type representing the raw barcode string. Processing this
first causes unnecessary database queries across all handlers before
checking explicitly parsed types (e.g. GS1).

Sort `parse_results` to push "unknown" types to the end of the loop,
ensuring that high-confidence, parsed barcode matches are evaluated first.
@OCA-git-bot
Copy link
Copy Markdown
Contributor

Hi @sebalix, @simahawk, @guewen,
some modules you are maintaining are being modified, check this out!

@OCA-git-bot OCA-git-bot added series:16.0 mod:shopfloor Module shopfloor mod:shopfloor_gs1 Module shopfloor_gs1 labels Jun 3, 2026
@nicolas-delbovier-acsone
Copy link
Copy Markdown
Author

@jbaudoux

Copy link
Copy Markdown
Contributor

@jbaudoux jbaudoux left a comment

Choose a reason for hiding this comment

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

Definitely better but not enough.
I think I explained it in the issue. You need to loop over each result and their type to refine the result.
First result is ean, search for products. Next result is lot, search for lots of found products. Etc...

@@ -1 +1 @@
from . import search
from . import barcode_parser
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

is this change really needed?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I am not against reverting this change if really you prefer so.

I was just applying the "boy scout rule" to bring this file name in line with naming conventions while I was working in the area.

@nicolas-delbovier-acsone
Copy link
Copy Markdown
Author

Definitely better but not enough. I think I explained it in the issue. You need to loop over each result and their type to refine the result. First result is ean, search for products. Next result is lot, search for lots of found products. Etc...

I do not understand how what you say could work? Ingeneric_find, once a record is found, the method returns (thus the importance of the ordering of the types). Therefore, there is no way to "refine" results for later searches...

Are you suggesting that we should not return on first result found and always test all possible types first and then decide which record I want to link to the returned SearchResult in case of collisions (e.g. lot and package sharing the same name) ? Wouldn't this make the search slower while in most cases such a collision should be rare? How do we decide which record is the best to return in case of multiple records found ?

@jbaudoux
Copy link
Copy Markdown
Contributor

jbaudoux commented Jun 4, 2026

Definitely better but not enough. I think I explained it in the issue. You need to loop over each result and their type to refine the result. First result is ean, search for products. Next result is lot, search for lots of found products. Etc...

I do not understand how what you say could work? Ingeneric_find, once a record is found, the method returns (thus the importance of the ordering of the types). Therefore, there is no way to "refine" results for later searches...

Are you suggesting that we should not return on first result found and always test all possible types first and then decide which record I want to link to the returned SearchResult in case of collisions (e.g. lot and package sharing the same name) ? Wouldn't this make the search slower while in most cases such a collision should be rare? How do we decide which record is the best to return in case of multiple records found ?

Yes you need to process all the results and parse according their type. The one to return is the last that made a match. If you match a lot, you return the lot. If you match only a product, you return a product.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:shopfloor_gs1 Module shopfloor_gs1 mod:shopfloor Module shopfloor series:16.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants