-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Performance: Cache salesrule attributes to prevent unnecessary database queries #40245
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
Conversation
|
The security team has been informed about this pull request due to the presence of risky security keywords. For security vulnerability reports, please visit Adobe's vulnerability disclosure program on HackerOne or email psirt@adobe.com. |
|
The security team has been informed about this pull request due to the presence of risky security keywords. For security vulnerability reports, please visit Adobe's vulnerability disclosure program on HackerOne or email psirt@adobe.com. |
Co-authored-by: ihor-sviziev <1873745+ihor-sviziev@users.noreply.github.com>
|
The security team has been informed about this pull request due to the presence of risky security keywords. For security vulnerability reports, please visit Adobe's vulnerability disclosure program on HackerOne or email psirt@adobe.com. |
…alesrule attributes are loaded Co-authored-by: ihor-sviziev <1873745+ihor-sviziev@users.noreply.github.com>
|
The security team has been informed about this pull request due to the presence of risky security keywords. For security vulnerability reports, please visit Adobe's vulnerability disclosure program on HackerOne or email psirt@adobe.com. |
Co-authored-by: ihor-sviziev <1873745+ihor-sviziev@users.noreply.github.com>
|
The security team has been informed about this pull request due to the presence of risky security keywords. For security vulnerability reports, please visit Adobe's vulnerability disclosure program on HackerOne or email psirt@adobe.com. |
1 similar comment
|
The security team has been informed about this pull request due to the presence of risky security keywords. For security vulnerability reports, please visit Adobe's vulnerability disclosure program on HackerOne or email psirt@adobe.com. |
|
The security team has been informed about this pull request due to the presence of risky security keywords. For security vulnerability reports, please visit Adobe's vulnerability disclosure program on HackerOne or email psirt@adobe.com. |
|
@magento run all tests |
|
@ihor-sviziev its better to identify a way to implement the fix without an additional Eav query. i.e load attributes if its a Write a combination of plugin & observers and set a flag then use it as condition would be the best way IMHO. For example Headful FE call and REST covered here For GraphQl |
|
@copilot address comment #40245 (comment) |
Co-authored-by: ihor-sviziev <1873745+ihor-sviziev@users.noreply.github.com>
|
The security team has been informed about this pull request due to the presence of risky security keywords. For security vulnerability reports, please visit Adobe's vulnerability disclosure program on HackerOne or email psirt@adobe.com. |
Refactored the implementation to use a cache-based approach instead of state management. The previous approach had potential concurrency issues with shared state. The new solution:
Changes in commit bf149f5 Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
The security team has been informed about this pull request due to the presence of risky security keywords. For security vulnerability reports, please visit Adobe's vulnerability disclosure program on HackerOne or email psirt@adobe.com. |
|
@senthilengg that was just test rub to check if copilot can fix the issues |
Overview
This PR fixes a performance issue where the
QuoteConfigProductAttributesplugin was loading sales rule product attributes on every cart query, even when discount calculations were not being performed. This caused unnecessary database queries to thesalesrule_product_attributetable and EAV attribute loading overhead on every cart page view.Problem
The
QuoteConfigProductAttributesplugin intercepts every call togetProductAttributes(), which fires whenever quote items are loaded - not just during totals collection. This means:salesrule_product_attribute)Example Query Fired Unnecessarily
Solution
Implemented a cache-based approach to store salesrule attributes and eliminate repeated database queries:
1. Modified QuoteConfigProductAttributes Plugin
Added cache layer to store and retrieve active attributes:
2. ClearProductAttributesCacheObserver
Added observer to automatically clear cache when sales rules are saved or deleted:
Registered for:
salesrule_rule_save_commit_aftereventsalesrule_rule_delete_commit_aftereventImpact
Performance Improvements
Behavior
Backward Compatibility
Testing
Unit Tests Added
QuoteConfigProductAttributesTest- Verifies cache behavior (read and write)ClearProductAttributesCacheObserverTest- Verifies cache clearing on rule save/deleteManual Verification
salesrule_product_attributequery fires and result is cachedFiles Changed
Model/Plugin/QuoteConfigProductAttributes.php- Added cache layerObserver/ClearProductAttributesCacheObserver.php- Cache invalidationetc/events.xml- Register cache clearing observersRelated Issue
Addresses the performance concern raised in the issue: "Magento\SalesRule\Model\Plugin\QuoteConfigProductAttributes::afterGetProductAttributes getting triggered on all Cart Queries"
This change provides significant performance benefits for merchants with large catalogs and many active sales rules, while maintaining complete backward compatibility and correct discount calculation behavior. The cache-based approach follows Magento best practices and eliminates concurrency concerns.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.