Forums / Developer / excel export: how to spare memory in tpl ?

excel export: how to spare memory in tpl ?

Author Message

Seb Gaillard

Wednesday 22 July 2009 12:10:58 pm

Hi,

I want to make an excel export of all content of a class in the same page.
I have some memory limit problem :

<b>Fatal error</b>:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 120061917 bytes) in <b>/var/www/psycho/var/mySite/cache/template/compiled/partners-68dce9a3d2b5c693cca5f961b1369a56.php</b> on line <b>688</b><br />

my excel file is generated by clicking on a link like this

<a href={concat('layout/set/excel/content/view/partners/(class)/mySite_interview')|ezurl()}>Interview</a>

As there is no possibility to navigate between differents pages (with offset parameter), I try to "simulate" the pagination mechanism like that

{def   $depth= 7
        $parentNodeId = 2
        $counter=0
	$offset=0
	$limit=25
	$filter_hash=true()
     $count = fetch('content','list_count',hash('parent_node_id', $parentNodeId,
								'main_node_only', true(),
								'depth', $depth,
								'class_filter_type', include,
								'class_filter_array', array($view_parameters.class )
								)
					)
     $ForLimit = ceil($count|div($limit))
     }
<html>
<meta http-equiv="Content-Type" content="text/html" charset="utf-8" />
<table style="border: 1px solid black">
<tr>
<td colspan="3" style="font-weight: bold; background-color: silver;">
Article [{$count}]
</td>
</tr>
<tr>
    <td></td>
    <td style="font-weight: bold;">Type of content</td>
    <td style="font-weight: bold;">Title</td>
</tr>
{for 0 to $ForLimit}
	{set $offset=$offset|sum($limit)
	$filter_hash=hash('parent_node_id', $parentNodeId,
						'main_node_only', true(),
						'limit', $limit,
						'offset', $offset,
				        'class_filter_type', 'include',
				        'class_filter_array', array( $view_parameters.class ),
				        'depth', $depth,
						)

	}
	{* by creating a new set of $elements, I hope to spare memory*}
        {def $elements=fetch('content','list',$filter_hash)}
	{foreach $elements as $element}
		<tr>
		    {set $counter = inc( $counter )}
		    <td>{$counter}</td>
		    <td>{$element.class_identifier|wash()}</td>
		    <td>{$element.name|wash()}</td>
		</tr>
	{/foreach}
	{* free memory ???*}
	{undef $elements}
{for}
</table>
</html>

But it doesn't work. Someone has a solution?

Max Keil

Wednesday 22 July 2009 4:41:49 pm

Hi Seb,

your last 3 line looks ike this! I see, that you forgot to close the "for" method?

{undef $elements}
{for}
</table>
</html>

For exporting huge information containers, I would prefer to use native PHP functions instead of Template code!

It's also not clean to def the same variable within the {for}{/for}. Use "set" for this and def the variable before the loop.

Mit freundlichen Grüßen
Best regards

Max Keil

____________________________________________________________
eZ Publish Gold Partner - http://www.all2e.com
http://ez.no/partners/worldwide_partners/all2e_gmbh

Seb Gaillard

Thursday 23 July 2009 12:35:39 am

Hi Max,

Effectively I forgot to close the for method... Now, it work's fine! I think that after a lot of hours with the nose through the code, I didn't see anything...

Otherwise, I create (def) the $elements varliable in each loop because I hope that "{undef}" free memory. Do you know:
1/ If it's true ?
2/ if I use {set ...}, the memory is spared too?

Do you know where can I find an exemple who "use native PHP functions instead of Template code" for doing this ?

Thank's,

Seb

Max Keil

Thursday 23 July 2009 5:43:53 pm

You're right,

undef should be more memory efficient.

native PHP: you can create a simple template fetch function or module which would do the same work for you and generate the html, but much more efficient - because of the loops and fetches.

Mit freundlichen Grüßen
Best regards

Max Keil

____________________________________________________________
eZ Publish Gold Partner - http://www.all2e.com
http://ez.no/partners/worldwide_partners/all2e_gmbh

eZ debug

Timing: Jan 31 2025 01:24:17
Script start
Timing: Jan 31 2025 01:24:17
Module start 'content'
Timing: Jan 31 2025 01:24:17
Module end 'content'
Timing: Jan 31 2025 01:24:17
Script end

Main resources:

Total runtime0.2331 sec
Peak memory usage8,192.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0094 588.0469370.2891
Module start 'content' 0.00940.0159 958.33591,005.7031
Module end 'content' 0.02530.2078 1,964.03913,897.0391
Script end 0.2331  5,861.0781 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00502.1482200.0003
Check MTime0.00150.6643200.0001
Mysql Total
Database connection0.00090.380510.0009
Mysqli_queries0.124453.35711410.0009
Looping result0.00160.70261390.0000
Template Total0.207388.910.2073
Template load0.00100.424210.0010
Template processing0.206388.482910.2063
Override
Cache load0.00070.302810.0007
Sytem overhead
Fetch class attribute can translate value0.00180.790110.0018
XML
Image XML parsing0.00030.126110.0003
General
dbfile0.00723.1095200.0004
String conversion0.00000.003930.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs