Forums / Developer / Fast fetch - getting only contentobject_id and name

Fast fetch - getting only contentobject_id and name

Author Message

Marcin Bogowski

Wednesday 15 November 2006 4:25:03 am

Hi,
I've got edit form with few generated <select> lists. Now editing works really slow, because I'm using e.g.
{def $forets = fetch('content','list', hash(parent_node_id,174, 'sort_by', array('name', true()) ))}
Creating objects takes long time and I only need 'contentobject_id' and 'name' of object.

<b>My question is:</b>
Does anybody know any way to get list of 'contentobject_id' and 'name' ?
Maybe some simple extension fetching objects as array, but only name and id (no data_map)?

Ps. {cache-block} is useless in edit forms.

Thanks,
Marcin

Xavier Dutoit

Wednesday 15 November 2006 8:21:41 am

Hi,

Why couldn't you use cache-block into an edit form ?

An otherwise, yes, you could write an extension to fetch only the id and the name (done it for an ajax subselect thing).
as long as it fi
Are you sure that it's slow because of your select ? the edit form might be painfully slow without that ;). Have a look at the powercontent extension, it might speed the process.

X+

http://www.sydesy.com

Kristian Hole

Wednesday 15 November 2006 8:26:53 am

Hi Marcin,

Welcome to the forum.

The datamap and other information is not fetched until you access it. Which means, even if you fetch the object, the datamap is not fetched until you access $object.data_map from the templates, or $object->attribute('data_map') in PHP.

As far as i know, the default fetchfunction only returns the objects. It should however be easy to create an extension which allows you to do what you want.

Kristian

http://ez.no/ez_publish/documenta...tricks/show_which_templates_are_used
http://ez.no/doc/ez_publish/techn...te_operators/miscellaneous/attribute

Kristian Hole

Wednesday 15 November 2006 8:28:44 am

If you want to make an extension with fetch functions, you can use this extension as basis:
http://ez.no/community/contribs/hacks/informationcollection_fetch_functions

Kristian

http://ez.no/ez_publish/documenta...tricks/show_which_templates_are_used
http://ez.no/doc/ez_publish/techn...te_operators/miscellaneous/attribute

Marcin Bogowski

Thursday 16 November 2006 3:42:29 am

Hi,
Thanks for answres!

I forgot add that select (multiple) contains 1000 rows - that's why it works so slowly. Don't ask me why it is done this way ;)

I resolved my problem writing really small extension:

$FunctionList['fastObjectFetch'] = array( 'name' => 'fastFetchObjects',
	'operation_types' => array( 'read' ),
	'call_method' => array( 'include_file' =>'extension/myOwn/modules/forest/FunctionCollection.php',
	'class' => 'ForetFunctionCollection',
	'method' => 'fastFetchObjects' ),
	'parameter_type' => 'standard',
	'parameters' => array(
			array( 
				'name' => 'node_id',
				'type' => 'integer',
				'required' => true ),
		)
);

and

function fastFetchObjects($node_id) 
{
$temp =  eZContentObjectTreeNode::subTree( array('AsObject' => false), $node_id);
return array( 'result' => $temp);
}

In template I use

{def $forets = fetch('forets', 'fastFetchObjects', hash('node_id', 174))}

instead of

{def $forets = fetch('content','list', hash(parent_node_id,174, 'sort_by', array('name', true()) ))}

And now it works much, much faster. Could you explain me why?

Proof:
Slow case:

Time accumulators:
Mysql Total				
Mysql_queries	8.2988 sec	31.8806%	125	0.0664 sec
Looping result	0.6058 sec	2.3272%	93	0.0065 sec
--
Template Total	25.3405 sec	 97.3%	 3	 8.4468 sec
Template load	1.7985 sec	6.9092%	3	0.5995 sec
Template parser: create text elements	0.0455 sec	0.1750%	1	0.0455 sec
Template parser: remove whitespace	0.0123 sec	0.0474%	1	0.0123 sec
Template parser: construct tree	0.2718 sec	1.0442%	1	0.2718 sec
Template load and register function	0.0166 sec	0.0637%	7	0.0024 sec
Template processing	23.5410 sec	90.4345%	3	7.8470 sec
--
Total script time:	26.0310 sec

Fast case:

Time accumulators:
Mysql Total				
Mysql_queries	0.3948 sec	8.9410%	124	0.0032 sec
Looping result	0.0719 sec	1.6276%	92	0.0008 sec
--
Template Total	3.7193 sec	 84.2%	 3	 1.2398 sec
Template load	1.7923 sec	40.5901%	3	0.5974 sec
Template parser: create text elements	0.0446 sec	1.0110%	1	0.0446 sec
Template parser: remove whitespace	0.0124 sec	0.2807%	1	0.0124 sec
Template parser: construct tree	0.2732 sec	6.1875%	1	0.2732 sec
Template load and register function	0.0164 sec	0.3709%	7	0.0023 sec
Template processing	1.9260 sec	43.6170%	3	0.6420 sec
--
Total script time:	4.4156 sec	

Marcin Bogowski

Thursday 16 November 2006 3:54:25 am

About {cache-block},
"Why couldn't you use cache-block into an edit form ?"

Maybe I missed something.
For example I've got two required fileds: name (text) and language (select). I sent form with empty name and selected language as 'polish'. Is it possible to set language on 'polish' again as it was selected? Form is in {cache-block} so when validation is wrong form will be displayed from cache. Does it work this way?

Thanks
Marcin

André R.

Thursday 16 November 2006 5:45:13 am

You can use the selected_id as cache-block key, if this content depends on user rights you should also use $current_user.role_id_list|implode( ',' ) and $current_user.limited_assignment_value_list|implode( ',' ) as keys.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Kristian Hole

Thursday 16 November 2006 9:53:07 am

Marcin:
To have a fair comparison, you should use the same sorting in both cases. Now you are sorting one, and not the other. The one who is not sorted is of course going to be faster :-)

Kristian

http://ez.no/ez_publish/documenta...tricks/show_which_templates_are_used
http://ez.no/doc/ez_publish/techn...te_operators/miscellaneous/attribute

Marcin Bogowski

Thursday 16 November 2006 10:08:58 am

Sorry, it was sample code;) I added sorting and it works also much faster. SQL is executed fast (ORDER BY isn't important here). Maybe creating objects makes script slower.

My updated function:

	function fastFetchObjects($node_id, $sort_field) 
	{
		$list =  eZContentObjectTreeNode::subTree( array('AsObject' => false, 'SortBy' => array( $sort_field, true )), $node_id);
		return array( 'result' => $list);
	}

Regarding "cache-block key". Can I really use selected_id as key? What will happen for edit form with 5 different selects (with 100 rows)? Block cache will be generated for each case?