Fix performance issue with retrieving association type codes - #82
Open
jakubtobiasz wants to merge 4 commits into
Open
Fix performance issue with retrieving association type codes#82jakubtobiasz wants to merge 4 commits into
jakubtobiasz wants to merge 4 commits into
Conversation
jakubtobiasz
commented
Oct 22, 2025
jakubtobiasz
commented
Oct 22, 2025
This change addresses issue CommerceWeavers#81 by optimizing how association type codes are retrieved in ProductNormalizer. Previously, the code used Api Platform's item provider to load entire ProductAssociation objects just to extract the type code, causing unnecessary object hydration for products with many associations. Changes made: - Created GetAssociationTypeCodeByAssociationIdQuery that uses a direct database query to fetch only the association type code - Updated ProductNormalizer to use the new query instead of ItemDataProviderInterface - Added query service configuration using XML (following the project's convention) - Updated unit tests to reflect the new implementation - Removed unnecessary validation logic from ProductNormalizer constructor The new implementation fetches only the required association type codes without hydrating unnecessary object data, significantly improving performance for products with many associations (1000+). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit addresses the PR feedback to ensure the query behavior can be properly extended by introducing an interface. Changes made: - Created GetAssociationTypeCodeByAssociationIdQueryInterface - Updated GetAssociationTypeCodeByAssociationIdQuery to implement the interface - Modified ProductNormalizer to depend on the interface instead of concrete class - Updated service configuration to alias the interface to the implementation - Updated unit tests to mock the interface This follows SOLID principles and allows for better extensibility and testability by programming to an interface rather than implementation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit addresses PR feedback to improve error handling by throwing an explicit exception instead of silently continuing when an association type code cannot be retrieved. Changes made: - Created ProductAssociationTypeNotFoundException with descriptive message including the association ID for better debugging - Updated ProductNormalizer to throw the exception instead of silently skipping associations with null type codes - Added unit test to verify the exception is thrown when type code is null This change improves debugging and makes error conditions explicit rather than silently failing, which is better for production systems where missing association type codes likely indicate a data integrity issue that should be addressed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
jakubtobiasz
force-pushed
the
claude/fix-issue-81-011CUNV4VpEYBHHMycNoQpbi
branch
from
October 22, 2025 16:40
9e676ff to
b84f9c2
Compare
jakubtobiasz
commented
Oct 22, 2025
jakubtobiasz
force-pushed
the
claude/fix-issue-81-011CUNV4VpEYBHHMycNoQpbi
branch
from
October 22, 2025 16:55
7038f1b to
55dd623
Compare
…nIdQuery This commit addresses the PHPStan error "Cannot access offset 'code' on mixed" by using getScalarResult() instead of getOneOrNullResult(). Changes made: - Changed from getOneOrNullResult() to getScalarResult() - Updated array access to $result[0]['code'] to properly access scalar results - Maintained null coalescing operator for handling empty results Using getScalarResult() provides better type safety as it returns a well-defined array structure that PHPStan can properly analyze, eliminating the type checking warnings. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
jakubtobiasz
force-pushed
the
claude/fix-issue-81-011CUNV4VpEYBHHMycNoQpbi
branch
from
October 22, 2025 17:02
55dd623 to
0f5cebf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This change addresses issue #81 by optimizing how association type codes are retrieved in ProductNormalizer. Previously, the code used Api Platform's item provider to load entire ProductAssociation objects just to extract the type code, causing unnecessary object hydration for products with many associations.
Changes made:
The new implementation fetches only the required association type codes without hydrating unnecessary object data, significantly improving performance for products with many associations (1000+).
Closes #81
🤖 Generated with Claude Code