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.

eZ debug

Timing: Jan 18 2025 02:12:54
Script start
Timing: Jan 18 2025 02:12:54
Module start 'layout'
Timing: Jan 18 2025 02:12:54
Module start 'content'
Timing: Jan 18 2025 02:12:55
Module end 'content'
Timing: Jan 18 2025 02:12:55
Script end

Main resources:

Total runtime0.7307 sec
Peak memory usage4,096.0000 KB
Database Queries91

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0044 589.0313152.6250
Module start 'layout' 0.00440.0022 741.656339.4453
Module start 'content' 0.00660.7226 781.1016746.9375
Module end 'content' 0.72920.0014 1,528.039128.1641
Script end 0.7307  1,556.2031 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00300.4145160.0002
Check MTime0.00130.1829160.0001
Mysql Total
Database connection0.00060.086810.0006
Mysqli_queries0.637187.1864910.0070
Looping result0.00090.1266890.0000
Template Total0.698595.620.3492
Template load0.00200.272520.0010
Template processing0.696595.315620.3482
Template load and register function0.00030.038210.0003
states
state_id_array0.00090.129310.0009
state_identifier_array0.00100.142220.0005
Override
Cache load0.00190.2560860.0000
Sytem overhead
Fetch class attribute can translate value0.00060.086740.0002
Fetch class attribute name0.00220.3046160.0001
XML
Image XML parsing0.00160.218740.0004
class_abstraction
Instantiating content class attribute0.00000.0057190.0000
General
dbfile0.00110.1548300.0000
String conversion0.00000.001140.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
13content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
13content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
6content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 35
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs