定制 blackbird/module-eav-optimize 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

blackbird/module-eav-optimize

Composer 安装命令:

composer require blackbird/module-eav-optimize

包简介

Improve EAV attribute option performance

README 文档

README

Description

The EavOptimize plugin provides a solution to optimize the performance of fetching attribute options in Magento 2. It introduces memoization and caching for EAV (Entity-Attribute-Value) attribute option values, which can improve store performance by reducing redundant database calls.

Additionally, this module forces the default value of cache_user_defined_attributes system configuration to 1, ensuring that custom attributes are cached by default for better efficiency. You can still disable this config in adminhtml.

See existing Magento issue: magento/magento2#36174 See in progress official PR: magento/magento2#39476

Features

  • Memoization: Stores attribute option values in memory for faster repeated access during the same request lifecycle.
  • Caching: Adds caching for custom attribute values fetched through getAttributeText() calls for improved overall performance.
  • Configuration Options in Admin Panel: Allows enabling or disabling caching through a Magento System Configuration field.
  • Default Caching Behavior: Automatically activates caching for custom attributes by setting cache_user_defined_attributes to 1 by default in the configuration.

Configuration

To manage the caching behavior, navigate to the Admin Panel:

  1. Go to Stores > Configuration > Advanced > Developer.
  2. Locate the Caching section.
  3. Check the Cache Attribute Options Values setting:
    • Yes (default): Enables caching for attribute option values retrieved using getAttributeText().
    • No: Disables caching.

Installation

  1. Install the module using composer:
    composer require blackbird/module-eav-optimize

  2. Run the following commands to register and enable the module:

    bin/magento module:enable Blackbird_EavOptimize
    bin/magento setup:upgrade
    bin/magento cache:flush

Technical Details

Why Use EavOptimize?

Fetching EAV attribute options using getAttributeText() in Magento can result in multiple redundant queries, especially in cases where multiple calls retrieve the same data. The EavOptimize plugin avoids such performance bottlenecks by leveraging memoization to reuse data within a single request and caching to persist retrieved attribute options across requests.

Changes Introduced

  • The plugin overrides or interacts with default Magento EAV functionality to add memoization for EAV attribute option values at runtime in the class Magento\Eav\Model\Entity\Attribute\Source\Table.
  • Adjustments are made to cache attribute options by default through config.xml:
    <default>
        <dev>
            <caching>
                <cache_user_defined_attributes>1</cache_user_defined_attributes>
                <cache_option_values>1</cache_option_values>
            </caching>
        </dev>
    </default>
  • A system configuration option has been added (system.xml) to allow admin users to control caching behavior (Cache Attribute Options Values).

Performance Benefits

  1. Reduces the number of database queries during attribute option lookups.
  2. Improves overall page load times, especially for pages that frequently query for attribute text (e.g., product pages, category pages).
  3. Ensures smoother performance under heavy load.

Compatibility

This module is compatible with:

  • Magento 2 version 2.3.x and above.
  • PHP version used should align with Magento's compatibility.

Usage Example

Without EavOptimize:

When fetching an attribute's option text multiple times (e.g., by calling getAttributeText() in a loop), Magento may execute redundant database calls to retrieve the same data repeatedly.

With EavOptimize:

The plugin stores these values in memory through memoization during runtime. For subsequent calls, the data is fetched directly from memory or cache instead of querying the database.

Example:

$product = $productRepository->getById(1);
echo $product->getAttributeText('color'); // First call - fetched from DB or cache
echo $product->getAttributeText('color'); // Second call - fetched from memoized storage

Enjoy improved performance while managing your EAV attributes with EavOptimize! 🚀

blackbird/module-eav-optimize 适用场景与选型建议

blackbird/module-eav-optimize 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.12k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2024 年 12 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 blackbird/module-eav-optimize 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 blackbird/module-eav-optimize 我们能提供哪些服务?
定制开发 / 二次开发

基于 blackbird/module-eav-optimize 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 8.12k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 11
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-16