View Issue Details

IDProjectCategoryView StatusLast Update
0002120OXID eShop (all versions)4.05. Performancepublic2012-12-10 13:29
Reportermkr Assigned To 
PrioritynormalSeveritycrashReproducibilityalways
Status resolvedResolutionno change required 
Product Version4.4.2 revision 29492 
Summary0002120: oxCategoryList::buildTree consume to much memory
DescriptionI build an exporter module and uses oxCategoryList::buildTree to create the category path like 'Cat1 > Cat2 > Cat3' from an acticle.

Using these function consume too much memory (with >500 article more than 536870912 bytes).

Some test with using oxList::clear result in the same problem.
Steps To Reproducecreate a export.php, with code seen on additional info, under InstallDir/modules/test e.g.
Use a Shop installation with more than 500 active articles.
The articles have to be assigned to categories.

Run the export.php script and watch memory consumprion. On my test run my toal system memory consumption run from 1558 MB to above 2100 MB before the test crashes, because of memory_limit restrictions.
Additional Information<?php

ini_set('session.name', 'sid' );
ini_set('session.use_cookies', 0 );
ini_set('session.use_trans_sid', 0);
ini_set('url_rewriter.tags', '');
ini_set('magic_quotes_runtime', 0);
ini_set('max_execution_time', 0 );

function getShopBasePath()
{
    return dirname(__FILE__).'/../../';
}

require_once(getShopBasePath().'/core/oxfunctions.php');
require_once(getShopBasePath().'/core/oxlist.php');
require_once(getShopBasePath().'/core/oxarticlelist.php');
require_once(getShopBasePath().'/core/oxcategorylist.php');
require_once(getShopBasePath().'/core/oxconfig.php');

$myConfig = oxConfig::getInstance()->getConfig();

$oArticleList = oxNew('oxarticlelist');
$oArticleList->selectString('SELECT * FROM oxarticles where oxactive = 1');

foreach($oArticleList as $oArticle) {
    $aNames = array();
    $sCatId = $oArticle->getCategory()->getId();
    
    $oCategoryTree = oxNew( 'oxCategoryList' );
    $oCategoryTree->buildTree($sCatId, $myConfig->getConfigParam( 'blLoadFullTree' ), $myConfig->getConfigParam( 'bl_perfLoadTreeForSearch' ), $myConfig->getConfigParam( 'blTopNaviLayout' ) );
        
    foreach($oCategoryTree->getPath() as $oCat) {
        array_push($aNames, $oCat->oxcategories__oxtitle->value);
    }
    
    $sCategoryTreePath = implode(' > ', $aNames);
}
TagsPerformance
Theme
BrowserAll
PHP Versionany
Database Versionany

Activities

birute_meilutyte

2010-10-29 13:51

reporter   ~0003652

@developers: please, check this issue from source code side

sarunas_valaskevicius

2011-01-28 16:14

reporter   ~0004028

hi, buildTree builds full category tree, and it (of course) has to consume some memory (array of category objects with title and other info).

repeatedly calling this function causes the memory usage to sum up, due to php handling of memory releases.

a better way to achieve this is to use oxCategory::getParentCategory() repeatedly.

still, a correct way is to make use of nested set functionality to select all category parents where oxleft < articleCategory.oxleft and oxright > articleCategory.oxright ordering by oxleft. this way you will get all parent categories ordered by their parental status.

simple sql:
select tree.oxtitle from oxcategories as me left join oxcategories as tree on me.OXLEFT >= tree.oxleft and me.OXRIGHT <= tree.OXRIGHT
where me.OXID='[end child category id]' order by tree.OXLEFT

note: use correct view name in select to select the correct language (for oxtitle).

mkr

2011-03-29 13:49

reporter   ~0004263

But this not what i expected.

1.
I need a broadcrumb path for an article. The buildTree function eliminates also hidden categories and so on. I think a pure sql statement will not mange this.

2.
The buildTree function is often used and consume so much memory. Ofther function like this, does not consume so much memory. So i think this bahivior should be be fixed to get a more stable software

dainius.bigelis

2011-04-27 15:45

reporter   ~0004410

Reminder sent to: mkr

hi,

In your case the Category tree is built in the foreach, what means, that it builds the tree in each cycle... what means - this way it really needs huge amount of memory.
So we suggest you to use the solution described by Sarunas in comment above. About hidden categories - for us it's not clear the purpose of showing that in the breadcrumb. i.e. what should be returned if the end of tree branch is hidden category... or it's in the middle.
So this is not the issue of eShop so the entry here is closed.

Best regards,