File tree Expand file tree Collapse file tree 4 files changed +66
-3
lines changed Expand file tree Collapse file tree 4 files changed +66
-3
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Copyright 2025 Adobe
4+ * All Rights Reserved.
5+ */
6+ declare (strict_types=1 );
7+
8+ namespace Magento \Catalog \Plugin ;
9+
10+ use Magento \Catalog \Api \CategoryManagementInterface ;
11+ use Magento \Catalog \Api \Data \CategoryTreeInterface ;
12+
13+ /**
14+ * Performance optimizer plugin for CategoryManagement
15+ */
16+ class CategoryManagementPerformanceOptimizer
17+ {
18+ private const DEFAULT_MAX_DEPTH = 3 ; // Limit depth to prevent timeouts
19+
20+ /**
21+ * Optimize getTree method with depth limits to prevent timeouts
22+ *
23+ * @param CategoryManagementInterface $subject
24+ * @param int|null $rootCategoryId
25+ * @param int|null $depth
26+ * @return array
27+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
28+ */
29+ public function beforeGetTree (
30+ CategoryManagementInterface $ subject ,
31+ $ rootCategoryId = null ,
32+ $ depth = null
33+ ): array {
34+ // Limit depth to prevent performance issues
35+ $ depth = $ depth ?? self ::DEFAULT_MAX_DEPTH ;
36+ return [$ rootCategoryId , $ depth ];
37+ }
38+ }
Original file line number Diff line number Diff line change 285285 <index referenceId =" CATALOG_CATEGORY_ENTITY_PATH" indexType =" btree" >
286286 <column name =" path" />
287287 </index >
288+ <!-- Performance optimization index for efficient tree traversal -->
289+ <index referenceId =" CATALOG_CATEGORY_ENTITY_PARENT_ID_LEVEL_POSITION" indexType =" btree" >
290+ <column name =" parent_id" />
291+ <column name =" level" />
292+ <column name =" position" />
293+ </index >
288294 </table >
289295 <table name =" catalog_category_entity_datetime" resource =" default" engine =" innodb"
290296 comment =" Catalog Category Datetime Attribute Backend Table" >
401407 <index referenceId =" CATALOG_CATEGORY_ENTITY_INT_STORE_ID" indexType =" btree" >
402408 <column name =" store_id" />
403409 </index >
410+ <!-- Performance optimization index for is_active attribute filtering -->
411+ <index referenceId =" CATALOG_CATEGORY_ENTITY_INT_STORE_ID_VALUE" indexType =" btree" >
412+ <column name =" store_id" />
413+ <column name =" value" />
414+ </index >
404415 </table >
405416 <table name =" catalog_category_entity_text" resource =" default" engine =" innodb"
406417 comment =" Catalog Category Text Attribute Backend Table" >
506517 <index referenceId =" CATALOG_CATEGORY_PRODUCT_PRODUCT_ID" indexType =" btree" >
507518 <column name =" product_id" />
508519 </index >
520+ <!-- Performance optimization index for product count queries -->
521+ <index referenceId =" CATALOG_CATEGORY_PRODUCT_CATEGORY_ID_PRODUCT_ID_POSITION" indexType =" btree" >
522+ <column name =" category_id" />
523+ <column name =" product_id" />
524+ <column name =" position" />
525+ </index >
509526 </table >
510527 <table name =" catalog_category_product_index" resource =" default" engine =" innodb"
511528 comment =" Catalog Category Product Index" >
Original file line number Diff line number Diff line change 157157 },
158158 "index" : {
159159 "CATALOG_CATEGORY_ENTITY_LEVEL" : true ,
160- "CATALOG_CATEGORY_ENTITY_PATH" : true
160+ "CATALOG_CATEGORY_ENTITY_PATH" : true ,
161+ "CATALOG_CATEGORY_ENTITY_PARENT_ID_LEVEL_POSITION" : true
161162 },
162163 "constraint" : {
163164 "PRIMARY" : true
216217 "index" : {
217218 "CATALOG_CATEGORY_ENTITY_INT_ENTITY_ID" : true ,
218219 "CATALOG_CATEGORY_ENTITY_INT_ATTRIBUTE_ID" : true ,
219- "CATALOG_CATEGORY_ENTITY_INT_STORE_ID" : true
220+ "CATALOG_CATEGORY_ENTITY_INT_STORE_ID" : true ,
221+ "CATALOG_CATEGORY_ENTITY_INT_STORE_ID_VALUE" : true
220222 },
221223 "constraint" : {
222224 "PRIMARY" : true ,
276278 "position" : true
277279 },
278280 "index" : {
279- "CATALOG_CATEGORY_PRODUCT_PRODUCT_ID" : true
281+ "CATALOG_CATEGORY_PRODUCT_PRODUCT_ID" : true ,
282+ "CATALOG_CATEGORY_PRODUCT_CATEGORY_ID_PRODUCT_ID_POSITION" : true
280283 },
281284 "constraint" : {
282285 "PRIMARY" : true ,
Original file line number Diff line number Diff line change 5151 <plugin name =" vendor_special_price_rest_plugin"
5252 type =" Magento\Catalog\Model\Plugin\SpecialPricePluginForREST\SpecialPriceStoragePlugin" />
5353 </type >
54+ <!-- Essential performance optimizations for category tree operations -->
55+ <type name =" Magento\Catalog\Api\CategoryManagementInterface" >
56+ <plugin name =" categoryManagementPerformanceOptimizer"
57+ type =" Magento\Catalog\Plugin\CategoryManagementPerformanceOptimizer" />
58+ </type >
5459</config >
You can’t perform that action at this time.
0 commit comments