Skip to content
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

Optimized EAV Cache #532

Closed
wants to merge 1 commit into from
Closed

Conversation

dng-dev
Copy link
Contributor

@dng-dev dng-dev commented Sep 21, 2018

This pull requests extends the eav cache to preload the entities and also cache them and reduce the amount of queries send to the Databases. In my Environment we reduced the amount of queries from 70 to 40. Also EAV Tags are added to cache entries to evict them on Attribute Save or Attribute set save etc. Also the Peak Memory usage gets lowered.

Here some Queries which gets executed once and cached.

SELECT `catalog_eav_attribute`.* FROM `catalog_eav_attribute` WHERE (attribute_id = :attribute_id);
SELECT `eav_entity_type`.`additional_attribute_table` FROM `eav_entity_type` WHERE (entity_type_id = :entity_type_id);
SELECT `eav_entity_type`.* FROM `eav_entity_type` WHERE (`eav_entity_type`.`entity_type_code`='catalog_product');

Copy link
Member

@colinmollenhour colinmollenhour left a comment

Choose a reason for hiding this comment

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

Looks great!

if (is_null($this->_productAttributes)) {
$this->_productAttributes = array_keys($this->getAttributesUsedInProductListing());
if (null === $this->_usedInProductListing) {
$this->_usedInProductListing = Mage::getSingleton('eav/config')->getAttributesUsedInProductListing();
}
return $this->_productAttributes;
Copy link
Member

Choose a reason for hiding this comment

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

Did you not mean to also update the return statement here?

Copy link
Contributor

Choose a reason for hiding this comment

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

What's the difference between getProductAttributes() and getAttributesUsedInProductListing()?

@colinmollenhour
Copy link
Member

One change I'm not crazy about is adding code that is specific to Mage_Catalog into Mage_Eav. I feel like Mage_Eav is meant to be a general purpose module and the methods with names containing "Product" belong in Mage_Catalog instead. While some efficiency is gained by putting these arrays all in the same cache record so that object data is not duplicated, I think it could be almost as efficient to store the catalog-specific data in a separate cache record and only store the attribute codes and then rehydrate the attribute arrays from the eav/config singleton.

@seansan
Copy link
Contributor

seansan commented Sep 24, 2018 via email

@tbaden tbaden added code change requested For Tickets where changes in code are needed, but seem mostly fine review needed Problem should be verified labels Jun 1, 2019
@IvanChepurnyi
Copy link
Contributor

Looks good, except moving product attribute related cache to eav/config. maybe makes sense to catalog related config model and use it to cache this specific catalog calls.

@dng-dev
Copy link
Contributor Author

dng-dev commented Jul 13, 2020

Will work on it in the next time

@github-actions github-actions bot added Component: Catalog Relates to Mage_Catalog Component: CatalogIndex Relates to Mage_CatalogIndex Component: Downloadable Relates to Mage_Downloadable Component: Eav Relates to Mage_Eav Component: Tax Relates to Mage_Tax labels Jul 24, 2020
@@ -310,7 +310,7 @@ public function getAttributeCodesByFrontendType($type)
*/
public function getStoreLabels()
{
if (!$this->getData('store_labels')) {
if (false === is_array($this->getData('store_labels'))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is_array() always returns a boolean. No need to do such a specific test here. It should just be !is_array()

$setIds = $this->_getSetIds();
if (!$setIds) {
if (false === is_array($setIds) || count($setIds) === 0) {
Copy link
Contributor

@joshua-bn joshua-bn Aug 21, 2020

Choose a reason for hiding this comment

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

if (!is_array($setIds) || !$setIds) {

@fballiano fballiano closed this Jun 2, 2022
@fballiano fballiano reopened this Jun 2, 2022
@fballiano fballiano changed the base branch from 1.9.3.x to 1.9.4.x June 2, 2022 11:15
@luigifab luigifab added the performance Performance related label Jan 19, 2023
@luigifab
Copy link
Contributor

I tried to resolve conflicts, but it's complicated for app/code/core/Mage/Eav/Model/Config.php. It crash for me (probably bad conflict resolving): invalid entity type.

I tried to only edit _load and _save, that's decrease number of sql request, but increase process time.
That's complicated.

@davidhiendl
Copy link
Contributor

davidhiendl commented Jan 20, 2023

@luigifab I have a working alternative/variant that is partially based on some of the logic from this PR as a module (I got impatient waiting for it to be merged over the years). It does however go a bit further (also caches EAV options by attribute set) and has been in production for multiple stores for quite some time. I could rewrite the module as a new PR against 20.x if this is still interesting to have?

@luigifab
Copy link
Contributor

All things that can reduce response time of OpenMage is interesting. If you can, I will very happy to test/use it.

@davidhiendl
Copy link
Contributor

@luigifab Alright, I will prepare it asap.

@davidhiendl davidhiendl mentioned this pull request Jan 24, 2023
@luigifab
Copy link
Contributor

luigifab commented Mar 4, 2023

Closed in favour of #2993.

@luigifab luigifab closed this Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code change requested For Tickets where changes in code are needed, but seem mostly fine Component: Catalog Relates to Mage_Catalog Component: CatalogIndex Relates to Mage_CatalogIndex Component: Downloadable Relates to Mage_Downloadable Component: Eav Relates to Mage_Eav Component: Tax Relates to Mage_Tax performance Performance related review needed Problem should be verified
Projects
None yet
Development

Successfully merging this pull request may close these issues.