Jump to content

Quickly count subcategories to speed up site loading time


gabbo876

Recommended Posts

I'm working on a site with a large category database > 3000 categories. I have successfully loaded my category list into phpmyadmin (tables in Myisam). However when attempting to load the site (localhost), the site times out.


The site times out after 30seconds and gets stuck on a subcategory count in php. Here's the line of code it gets stuck at while loading:
 

function GetSubCatCount($catid){
global $db, $the_cats;

$count = 0;

foreach($the_cats as $cat){
    if(isset($cat->category_parent)){
        if($cat->category_parent == $catid && $cat->category__auto_id <> 0 && $cat->category_lang == $dblang)
        { 
            $count = $count + 1;
        }
    }
}

return $count;
}

This counting method seems rather slow. How can I speed up the count of the subcategories in php or have Mysql send the subcategory count values?

 

 

Thanks and Regards!

 

 
Database: pligg
Table: pligg_categories

 

Table details:

 

|category__auto_id |category_lang |category_id |category_parent |category_name |category_safe_name |rgt |lft |category_enabled |category_order |category_desc |category_keywords |category_author_level |category_author_group |category_votes |category_karma

 

Software version: 5.5.25a - MySQL Community Server (GPL)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.