Fetches in frontpage template

Author Message

Kévin S.

Tuesday 06 July 2010 7:37:57 am

Hello everyone !

I'm new to eZ Publish, and I need some advice to better understand how
to use the template system.

Here is my problem : in the frontpage template, I have to fetch some
nodes of different types to display them on the home page of my site.
- Should I use 4 or 5 "small" fetches, or rather one big fetch to get
all the nodes I need (and then split it in smaller arrays) ?
- I could also create content objects that are bond to the ones I
need (for example a "news" block that displays the news it is bond
to).
- Another solution could be to include other templates without
creating content objects, using "{include uri = ...}"

I have not enough experience to know the pros and the cons of each solution.
Which one would you advise me to use, for better performance and code
cleanliness ?

Thanks in advance,

Kévin

Gaetano Giunta

Tuesday 06 July 2010 8:10:10 am

simply put: test

- enable debugging

- look at nr. of sql queries used, total memory used in debug output

- change from one fetch to many fetches, and see the difference

Also, the vital advice:

- do not forget to put a cache block around your fetches in the pagelayout!

Principal Consultant International Business
Member of the Community Project Board

Kévin S.

Tuesday 06 July 2010 8:55:06 am

OK, thank you for the tip !

What about the structure of the template ? Would you use several small templates, or one big ?

André R.

Tuesday 06 July 2010 10:06:28 am

If possible, use relations, either as object / attribute / embed (ezxmltext) relations instead of hardcoding the fetch in your front page template. So that viewcache.ini can setup to make sure page is always up to date. (when you hardcode you will probably end up having to disable cache, which is a wast and makes it slow).

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

Kévin S.

Tuesday 06 July 2010 12:50:18 pm

OK, I had thought about trying to use relations instead of fetches, but I wasn't sure it had a real consequence.

For the cache, you are talking about disabling the cache while I'm coding, right ? I have actually disabled my browser's cache, and each time I make a change in my template I have to empty eZ Publish's one to see it on the site.

Could you explain me what is viewcache.ini's role ? It seems to provide a little control of cache updating when pages are loaded, but the documentation it is quite laconic ...

Thank you for your answer !

Peter Keung

Tuesday 06 July 2010 5:09:14 pm

In short, the rules you define in viewcache.ini will determine what other objects' viewcaches should be cleared when objects of different classes are edited and published.

This article is a good intro:

http://ez.no/doc/ez_publish/technical_manual/4_x/features/view_caching/smart_view_cache_cleaning

http://www.mugo.ca
Mugo Web, eZ Partner in Vancouver, Canada

Kévin S.

Wednesday 07 July 2010 12:43:40 am

OK, thank you for this precision Peter. I'll have to learn more about caching !

Can anyone tell me the best solution, according to them, between creating a specific content class to show my objects on the frontpage (access to nodes are made within its template), or directly get my nodes content in frontpage.tpl ?

Gaetano Giunta

Wednesday 07 July 2010 12:58:30 am

If the objects you want to display in the frontpage are either

- direct children of the frontpage (even multipositioning can do), or

- linked to the fp via an object-relation (from fp to obj)

you will not need to meddle with smartviewcache.ini: the standard caching rules of eZP will make it so that when you update your objects your fp will be expired too.

In both cases, to display the objects within the frontpage, you will have to put a fetch in your fp template - not sure what you meant with 'creating a specific content class vs. directly getting the node's content'...

Using $node.children instead of a fetch amounts to (almost) the same query being executed on the db.

Principal Consultant International Business
Member of the Community Project Board

Kévin S.

Wednesday 07 July 2010 1:28:20 am

The objects I want to display are not direct children of the frontpage. Linking them to it is a good idea, thank you ! But I can't link all of them, because some are dynamic, I don't know in advance what object will require to be shown on the frontpage...

I meant creating a class (for example "News Block" ), and linking its instance to the objects (the news) I need to display. The instance of the new class is a child of the frontpage, so with a custom template I can display all linked objects. In frontpage.tpl I have just "{content_view_gui content_object = $newsBlock}". I don't really like this solution because it does not add any content, it just show existing content in a specific way, so I think I shouldn't create a class for that.

"Directly get the node contents" meant that I get – with a fetch or with relations – all the content I want to display just in frontpage.tpl.

Gaetano Giunta

Wednesday 07 July 2010 3:18:23 am

The 'block' class is not a bad idea - in fact I have used it in many projects - most of the time not in the frontpage, but rather in the lateral columns of the pagelayout.

It will of course involve some specific caching configuration, as there will be no direct link between your news and the hp (you might remove the view cache from the hp template and let it refresh eg; ever 15 minutes - look at online docs for the cache-block template function to learn more.

Otoh what you are describing here is exactly what the class "frontpage" from the ezflow extension does! Do you have any specific reason for not going the ezflow route?

Principal Consultant International Business
Member of the Community Project Board

Kévin S.

Wednesday 07 July 2010 4:02:27 am

OK for the cache, I will take a look to the doc, I don't know a lot of it yet...

I do not use the ezflow extension. I've taken the frontpage of ezwebin (maybe it's the same than ezflow), and I have overriden its template.

The structure of my site does not look like ezwebin's one : just under my home page (frontpage class) I have two other frontpages that shouldn't appear on the home page. Only the children and grand-children of these sub-frontpages are shown. This is why I can't do as ezwebin.

@Gaetano : I've finished my tests, and with fetches mysql queries take more time (~20% of total time) than using children relations (~7% of total time)

Gaetano Giunta

Wednesday 07 July 2010 8:33:07 am

The total time spent on different things to build the page is imho a red herring. It distracts developers so much that we should in fact remove it from debug output, plain and simple.

With a modern server and a php accelerator installed, your html pages will deliver in under 1 sec anyway. All the rest of the perceived page loading time is reduced by optimizing the construction of the html and properly setting up http headers (all the things that pagespeed and yslow are very good at telling you)

What will kill your site's scalability is otoh what is reported by following two metrics:

- number of queries executed

- memory used

ps: you can install ezflow after the fact if you want...

Principal Consultant International Business
Member of the Community Project Board

Kévin S.

Wednesday 07 July 2010 9:12:44 am

OK, so these percentages are not good information.

I will try first to understand ezwebin templates, and if needed I will install ezflow.

Thank you for sharing your experience :)

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.