Page 1 of 1

Phoca Tree Module slows down webpage loading

Posted: 01 Jul 2008, 09:49
by lukchmiel
Hi,
I've found Phoca Gallery component a great tool. I have created a very nice portfolio and after that I've downloaded Phoca Tree Module to make the navigation easier. It suprised me that after installing this module and publishing it on the left bar, the time of loading the webpage has increased dramatically even the page only with text (no photos). Unfortunately I had to switch this module off after many complaints from users, though it is a very useful module. Do you have any idea what could be the reason of such a long time loading ?
Lukasz

Re: Phoca Tree Module slows down webpage loading

Posted: 01 Jul 2008, 10:26
by Jan
No idea, there is a recursive function which search all menu items and subitems but I think, it cannot be so slowly :idea:

Re: Phoca Tree Module slows down webpage loading

Posted: 02 Jul 2008, 15:12
by lukchmiel
Hi,
I checked your demo website
f.e.
https://www.phoca.cz/phocagallery/demo/i ... ory/3-wine
and it seems it is loading a little bit slowly too (when you click links within or outsite gallery f.e. on article), but it is reasonble timing here. On my website though there are 4 times more categories and it was veeery slow loading. Interestingly, I use sobi2 tree module (for sharing different kind of files), which uses the same menu and the same number of categories, and it doesn't effect site at all.
Hope you solve this issue, because it is great and convenient module.
Greetings
Lukasz

Re: Phoca Tree Module slows down webpage loading

Posted: 05 Jul 2008, 01:21
by Jan
does the sobi check the permissions and parameters:

- if the category is for registered
- if the category is for special
- if the category is a private category (check for users)
- combinations of all permissions and rights
- if there should be displayed private or special or registered categories
- check for the user defined categories id which should not be displayed in the tree (parameters - hide categories you want in tree)
- check for the possible Itemid
- resorting the array because of possible categories which will be not displayed (permissions, rights, user defined)

...

Jan

Re: Phoca Tree Module slows down webpage loading

Posted: 10 Jul 2008, 13:39
by Shuairan
I think i figured out the problem: Like i wrote in another thread ( Tree Modul is evil ) your algorithm isn't as good as it could be. But this isn't the problem, with my 25galleries the foreach ( $data as $value ) (mod_phocagallery_tree.php, l.110) loops all in all 650times, that shouldn't slow down a page that much.

The problem is the call to $link = getLink ( $value->id ); (l.110) which is done several times too often:
I attached a modified version that counts the different calls and loops and prints the result.
With 25 categories it looks like this:
categoryTree(...): 26
foreach ( $data as $value ): 650
if ($value->parentid == $id) 25
function getLink( $id ) 650
Database requests: 650
As you can see, for every foreach-loop the getLink function is called (650 times), and with my test categories it always reachs the else-case and fires a database request (also 650 times!!!).
So if your mySQL Database is a little bit busy/slow that will cause enormous load time.

The funny thing is that the result of this is only needed in the 25cases when if ($value->parentid == $id) (l.114) hits, because only then the assignment $tree[$value->id] = $showText; (l.116) is done.

As i wrote already in the other thread, it is possible to speed up the tree-building by changing the function a litte bit, put l.112 and l.113 into the if-statement and imho it will run much faster.

here the modified function: (l.108-l.121)

Code: Select all

// Create category tree
function categoryTree( $data, $tree, $id=0, $text='', $treeId )
{		
	foreach ( $data as $value )
	{	
		if ($value->parentid == $id)
		{
			$link = getLink ( $value->id );
			$showText =  $text . ''.$treeId.'.add('.$value->id.','.$value->parentid.',\''.addslashes($value->text).'\',\''.$link.'\');'."\n";
			$tree[$value->id] = $showText;
			$tree = categoryTree($data, $tree, $value->id, '', $treeId);	
		}
	}
	return($tree);
}
So maybe you try this one and compare the load time. I think the algorithm with cubic complexity is still not the best, but i think nobody will have so much categories that this really slows down a page noticeablely.
---
Shuairan

Re: Phoca Tree Module slows down webpage loading

Posted: 13 Jul 2008, 21:42
by Jan
Great, thank you for this information. I will fix it.

Thank you, Jan