Skip to content

Fix performance issue with retrieving association type codes - #82

Open
jakubtobiasz wants to merge 4 commits into
CommerceWeavers:mainfrom
jakubtobiasz:claude/fix-issue-81-011CUNV4VpEYBHHMycNoQpbi
Open

Fix performance issue with retrieving association type codes#82
jakubtobiasz wants to merge 4 commits into
CommerceWeavers:mainfrom
jakubtobiasz:claude/fix-issue-81-011CUNV4VpEYBHHMycNoQpbi

Conversation

@jakubtobiasz

@jakubtobiasz jakubtobiasz commented Oct 22, 2025

Copy link
Copy Markdown
Member

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:

  • 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+).

Closes #81

🤖 Generated with Claude Code

Comment thread src/Doctrine/Query/GetAssociationTypeCodeByAssociationIdQuery.php Outdated
Comment thread src/Api/Normalizer/ProductNormalizer.php
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
jakubtobiasz force-pushed the claude/fix-issue-81-011CUNV4VpEYBHHMycNoQpbi branch from 9e676ff to b84f9c2 Compare October 22, 2025 16:40
Comment thread src/Doctrine/Query/GetAssociationTypeCodeByAssociationIdQuery.php Outdated
@jakubtobiasz
jakubtobiasz force-pushed the claude/fix-issue-81-011CUNV4VpEYBHHMycNoQpbi branch from 7038f1b to 55dd623 Compare October 22, 2025 16:55
…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
jakubtobiasz force-pushed the claude/fix-issue-81-011CUNV4VpEYBHHMycNoQpbi branch from 55dd623 to 0f5cebf Compare October 22, 2025 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Performance] Suboptimal retrieving association codes

2 participants