Share » Forums » Setup & design » Some idea to speedup code

Some idea to speedup code

Some idea to speedup code

Saturday 24 March 2007 1:52:53 am - 7 replies

Modified on Saturday 24 March 2007 2:03:18 am by Matteo Tomasini

Author Message

kracker (the)

The Doctor

Saturday 24 March 2007 2:32:01 am

@Matteo,

While I am impressed with your first post being so very detailed,
I fear the first thought when I glanced at your first post was ....

Most of this code belongs in php instead of tpl.

In moving the logic (up the chain-o-command) to php (I think) you will the gain motivating performance improvements you seek.

You might want to take a look at using the Wrap Operator extension which can provide a simple flexible way to write a php code which can return results inside of a template using a custom template operator. http://ezpedia.org/wiki/en/ez/wrap_operator

<i>//kracker

Audio Book - Noam Chomsky : Failed States Unabridged</i>

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

Matteo Tomasini

Monday 26 March 2007 1:14:54 am

@kracker

Thanks for the answer! Now it works!

kracker (the)

The Doctor

Monday 26 March 2007 1:25:54 am

@Matteo Tomasini

Your welcome. I'm glad.

Would you be willing to share your solution?
You could simply post it here in the forum.

Respectfully,
//kracker

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

Matteo Tomasini

Monday 26 March 2007 1:44:19 am

This is the code in the template

{def $kinds=array('Bene culturale','Luogo rupestre','Paesaggio/Attrazione naturale','Flora/Fauna')}
{def $places=fetch('content','list',hash(parent_node_id,59))}
{foreach $places as $place}
  {def $content=concat('<a href=',$place.path_identification_string|ezurl(no),' ><b>',$place.object.data_map.name.data_text,'</b></a> - ',$place.creator.name,'<br />')}
  {def $insertions=fetch('content','list',hash(parent_node_id,$place.node_id,
									 order_by,array('published',true()),class_filter_type, "include", class_filter_array, array(17)) ) }
  {set $content=concat($content,'<br /><b>Tipologia:</b>',wrap_user_func('generateMarkerContent', array($kinds,2,$insertions)))}

{*then I pass the $content variable to the function addMarker of the Google Maps*}

The values passed to the 'generateMarkerContent' function represent the list of kinds, the array position of the Selection attribute 'kind' and the list of insertions associated to a place.

This is the 'generateMarkerContent' function

function generateMarkerContent($list,$type,$insertions)
{
	$count=array();
	$allKinds=array();
	foreach($insertions as $insertion) {
	  end($insertion->ContentObject->ContentObjectAttributes);
	  $curr=current($insertion->ContentObject->ContentObjectAttributes);
	  array_push($allKinds,$list[$curr['eng-GB'][$type]->DataText]);
	}
	$count=array_count_values($allKinds);
	arsort($count);
	$str='';
	for ($i=0; $i<3; $i++)
	{
	  $curr=each($count);
	  if (isset($curr['key']))
	    $str=$str . ' ' . $curr['key'] . '(' . $curr['value'] . ')';
	}
	if (count($count)>3)
	  $str=$str . ' ...'
	
	return ($str);
}
?>

it returns a string containing the 3 most rated kinds

Xavier Dutoit

Monday 26 March 2007 3:03:41 pm

Hi,

What was the impact on speed ?

X+

http://www.sydesy.com

Matteo Tomasini

Monday 26 March 2007 11:13:12 pm

@Xavier Dutoit

Before the modification the template processing time was about 8 seconds, now is less than a second. During this time the CPU works at 100% (I have an AMD Athlon 64 3500+). The page has 5 places and about 20 Insertions.
Now I have inserted 9 places with about 50 Insertions and the template time is about 1.8sec, always with the CPU at 100%. I am quite worried about that, with about 100 places and 1000-1500 Insertions what will be the load page time? Have you got some more ideas to improve speed of my page?
Thanks

Xavier Dutoit

Tuesday 27 March 2007 2:47:29 am

Hi,

Assuming places and so on aren't going to change that often, use cache-block around them (with the right keys and update only when a new place is published, no time out). That's still as slow the first time, but much quicker the other times.

Have a look at the documentation.

X+

http://www.sydesy.com

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu