-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Improve getCustomAttribute() performance #13308
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
Merged
magento-engcom-team
merged 12 commits into
magento:2.3-develop
from
schmengler:custom-attributes-performance
Feb 22, 2018
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
08ab509
Refactor: move interface attributes array to interface itself
schmengler 74deee4
Move getCustomAttributeCodes from product model to resource model
schmengler 53e03b2
Update unit tests
schmengler ddc1b03
Move getCustomAttributeCodes from category model to resource model
schmengler e69be44
Add missing method call for reflection class name
schmengler ab558bd
Fix error with uninstantiated resource model
schmengler 7d4523c
Make new properties private
schmengler 98a9c36
WIP: GetCustomAttributeCodes service
schmengler 8378eff
Move retrieval of custom attributes to dedicated services
schmengler c587d3a
Merge branch '2.3-develop' into custom-attributes-performance
nmalevanec 208b1ec
Test stabilization.
nmalevanec f286a98
Test stabilization.
nmalevanec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
37 changes: 37 additions & 0 deletions
37
app/code/Magento/Catalog/Model/Entity/GetCategoryCustomAttributeCodes.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Catalog\Model\Entity; | ||
|
||
use Magento\Catalog\Api\Data\CategoryInterface; | ||
use Magento\Eav\Model\Entity\GetCustomAttributeCodesInterface; | ||
use Magento\Framework\Api\MetadataServiceInterface; | ||
|
||
class GetCategoryCustomAttributeCodes implements GetCustomAttributeCodesInterface | ||
{ | ||
/** | ||
* @var GetCustomAttributeCodesInterface | ||
*/ | ||
private $baseCustomAttributeCodes; | ||
|
||
/** | ||
* @param GetCustomAttributeCodesInterface $baseCustomAttributeCodes | ||
*/ | ||
public function __construct( | ||
GetCustomAttributeCodesInterface $baseCustomAttributeCodes | ||
) { | ||
$this->baseCustomAttributeCodes = $baseCustomAttributeCodes; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function execute(MetadataServiceInterface $metadataService): array | ||
{ | ||
$customAttributesCodes = $this->baseCustomAttributeCodes->execute($metadataService); | ||
return array_diff($customAttributesCodes, CategoryInterface::ATTRIBUTES); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
app/code/Magento/Catalog/Model/Entity/GetProductCustomAttributeCodes.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Catalog\Model\Entity; | ||
|
||
use Magento\Catalog\Api\Data\ProductInterface; | ||
use Magento\Eav\Model\Entity\GetCustomAttributeCodesInterface; | ||
use Magento\Framework\Api\MetadataServiceInterface; | ||
|
||
class GetProductCustomAttributeCodes implements GetCustomAttributeCodesInterface | ||
{ | ||
/** | ||
* @var GetCustomAttributeCodesInterface | ||
*/ | ||
private $baseCustomAttributeCodes; | ||
|
||
/** | ||
* @param GetCustomAttributeCodesInterface $baseCustomAttributeCodes | ||
*/ | ||
public function __construct( | ||
GetCustomAttributeCodesInterface $baseCustomAttributeCodes | ||
) { | ||
$this->baseCustomAttributeCodes = $baseCustomAttributeCodes; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function execute(MetadataServiceInterface $metadataService): array | ||
{ | ||
$customAttributesCodes = $this->baseCustomAttributeCodes->execute($metadataService); | ||
return array_diff($customAttributesCodes, ProductInterface::ATTRIBUTES); | ||
} | ||
} |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constants removal from class and moving them to interface is backward incompatible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
TheClass::THE_CONSTANT
still worksThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@schmengler
Possible fatal error if there is another implementation of the interface with same constant name declaration.
But this is more like the theoretical issue.
Currently, I raised this question for voting on the Internal Architectural Council to allow moving constants preserving names and values from Implementation to Interface being implemented. And thus fix our Backward Compatibility Guideline http://devdocs.magento.com/guides/v2.2/contributor-guide/backward-compatible-development/index.html saying
And to adapt internal tests which break on such changes.
I will get back to you shortly as soon as get results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maghamed It wouldn't even be a problem: https://3v4l.org/H4mYd 😄