@@ -656,25 +656,43 @@ protected function makeTempCategoryTreeIndex()
656
656
*/
657
657
protected function fillTempCategoryTreeIndex ($ temporaryName )
658
658
{
659
- // This finds all children (cc2) that descend from a parent (cc) by path.
660
- // For example, cc.path may be '1/2', and cc2.path may be '1/2/3/4/5'.
661
- $ temporarySelect = $ this ->connection ->select ()->from (
662
- ['cc ' => $ this ->getTable ('catalog_category_entity ' )],
663
- ['parent_id ' => 'entity_id ' ]
664
- )->joinInner (
665
- ['cc2 ' => $ this ->getTable ('catalog_category_entity ' )],
666
- 'cc2.path LIKE ' . $ this ->connection ->getConcatSql (
667
- [$ this ->connection ->quoteIdentifier ('cc.path ' ), $ this ->connection ->quote ('/% ' )]
668
- ),
669
- ['child_id ' => 'entity_id ' ]
670
- );
659
+ $ offset = 0 ;
660
+ $ limit = 500 ;
671
661
672
- $ this ->connection ->query (
673
- $ temporarySelect ->insertFromSelect (
674
- $ temporaryName ,
675
- ['parent_id ' , 'child_id ' ]
676
- )
677
- );
662
+ $ categoryTable = $ this ->getTable ('catalog_category_entity ' );
663
+
664
+ $ categoriesSelect = $ this ->connection ->select ()
665
+ ->from (
666
+ ['c ' => $ categoryTable ],
667
+ ['entity_id ' , 'path ' ]
668
+ )->limit ($ limit , $ offset );
669
+
670
+ $ categories = $ this ->connection ->fetchAll ($ categoriesSelect );
671
+
672
+ while ($ categories ) {
673
+ $ values = [];
674
+
675
+ foreach ($ categories as $ category ) {
676
+ foreach (explode ('/ ' , $ category ['path ' ]) as $ parentId ) {
677
+ if ($ parentId !== $ category ['entity_id ' ]) {
678
+ $ values [] = [$ parentId , $ category ['entity_id ' ]];
679
+ }
680
+ }
681
+ }
682
+
683
+ if (count ($ values ) > 0 ) {
684
+ $ this ->connection ->insertArray ($ temporaryName , ['parent_id ' , 'child_id ' ], $ values );
685
+ }
686
+
687
+ $ offset += $ limit ;
688
+ $ categoriesSelect = $ this ->connection ->select ()
689
+ ->from (
690
+ ['c ' => $ categoryTable ],
691
+ ['entity_id ' , 'path ' ]
692
+ )->limit ($ limit , $ offset );
693
+
694
+ $ categories = $ this ->connection ->fetchAll ($ categoriesSelect );
695
+ }
678
696
}
679
697
680
698
/**
0 commit comments