LISE - Very slow template/output

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
webform
Power Poster
Power Poster
Posts: 466
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

LISE - Very slow template/output

Post by webform »

I have 2 LISE Instances; Projects & Reports/Estimates.
A project can have many reports/estimates with version numbers.

I need to output projects only if the project have both an estimate & a report attached.

I use this summary template to output, and it works as expected except it's very very slow. There is only 30 projects in LISEProjects (and >200 reports/estimates), but it takes nearly 10 seconds to load:

Code: Select all

{if $items|@count > 0}{strip}
{foreach from=$items item=item name=data}
	{* FIND LATEST REVISION & GET ID *}
	{LISEReports xs_project = $item->item_id xs_type = 'Estimate' xs_scenario = 'Lift' pagelimit='1' orderby='custom_revision|DESC' template_summary='get_id' assign='estimate'}
	{LISEReports xs_project = $item->item_id xs_type = 'Report' xs_scenario = 'Lift' pagelimit='1' orderby='custom_revision|DESC' template_summary='get_id' assign='report'}

	{* OUTPUT ONLY IF ESTIMATE & REPORT IS PRESENT *}	
	{if !empty($estimate) && !empty($report)}
		DISPLAY PROJECT DATA.
	{/if}
{/foreach}
{/strip}{/if}
Is there another way to do it, so i can speed up the output? Any suggestions is very welcome.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1936
Joined: Mon Jan 29, 2007 4:47 pm

Re: LISE - Very slow template/output

Post by Jo Morg »

There are a number of reasons why it can take a long time to render, in particular bad use of the templates for each tag call.
I'd start by changing the main template a bit:

Code: Select all

{strip}
  {foreach from=$items item=item name=data}
    {* FIND LATEST REVISION & GET ID *}
    {LISEReports xs_project = $item->item_id xs_type = 'Estimate' xs_scenario = 'Lift' pagelimit='1' orderby='custom_revision|DESC' template_summary='get_id' assign='estimate'}
    {LISEReports xs_project = $item->item_id xs_type = 'Report' xs_scenario = 'Lift' pagelimit='1' orderby='custom_revision|DESC' template_summary='get_id' assign='report'}
    {* OUTPUT ONLY IF ESTIMATE & REPORT IS PRESENT *}
    {if !empty($estimate) && !empty($report)}
      DISPLAY PROJECT DATA.
    {/if}
  {foreachelse}
      {** NO DATA FOUND **}
  {/foreach}
{/strip}
I wouldn't assign each call to LISEReports to a var, but use different templates for each...
How far I'd change the templates depends on how you are using them, so the above is just a sample of something that can be simplified.
If you post here the LISEReports template I may be able to suggest a few more optimizations.
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
webform
Power Poster
Power Poster
Posts: 466
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

Re: LISE - Very slow template/output

Post by webform »

Thanks som much for your suggestions!

The LISEReports "get_id" template is only getting the Item ID for the found report. I'm only using the LISEReports "get_id" template, so i can filter the output if !empty($estimate) && !empty($report) in the Project template, as it's a simple template only containing the item_id:

Code: Select all

{if $items|@count > 0}{strip}
	{foreach from=$items item=item name=row}
		{$item->item_id}{if not $smarty.foreach.row.last},{/if}
	{/foreach}
{/strip}{/if}
The output from the LISEProject template, am i using to display a barchart (Chart.js). So my full LISEProject template is:

Code: Select all

{foreach from=$items item=item name=data}
	{* FIND LATEST REVISION & GET ID *}
	{LISEReports xs_project = $item->item_id xs_type = 'Estimate' xs_scenario = 'Lift' pagelimit='1' orderby='custom_revision|DESC' template_summary='get_id' assign='estimate'}
	{LISEReports xs_project = $item->item_id xs_type = 'Report' xs_scenario = 'Lift' pagelimit='1' orderby='custom_revision|DESC' template_summary='get_id' assign='report'}

	{* OUTPUT ONLY IF ESTIMATE & REPORT IS PRESENT *}	
	{if !empty($estimate) && !empty($report)}
		"{$item->title} {$item->fielddefs.project_name.value}"{if not $smarty.foreach.data.last},{/if}
	{/if}
	
{/foreach}
The final output results in about half of the 30 projects match the criteria and outputs to the barchart.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1936
Joined: Mon Jan 29, 2007 4:47 pm

Re: LISE - Very slow template/output

Post by Jo Morg »

Sorry for the late reply.
I believe that, for the low number of records you have stated you have, there may be something else at play there. However, if I understood correctly, you need to only check for not empty condition, meaning any one record would make it true, no need to count them all. I would break the loop at the 1st found on the inner templates:
https://smarty-php.github.io/smarty/4.x ... ach/#break
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3492
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: LISE - Very slow template/output

Post by velden »

Several solutions/work-arounds come to my mind

- Direct SQL. Perhaps not best-practive but using a Smarty template engine for this logic isn't either.
- Not sure if the LISE query class could help out here
- Using a back reference in the Project items. E.g. a UDT that on the Post-Save event (Event Manager) of a Report and Estimate, adds its own ID to the connected Project. You could use custom fielddefs to store those or (mis)use the already present and hidden fields key1, key2 and key3. In this case you only have to search the Projects that have both fields (Reports and Estimates) filled.
webform
Power Poster
Power Poster
Posts: 466
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

Re: LISE - Very slow template/output

Post by webform »

Many thanks for the suggestions. I am truly grateful for that.

I have tried installing on an external commercial server and here the loading time is halved. So my local server could easily be a big part of the problem.

I'll have to see what I can do to further reduce the load time.

The website is only used locally/internally (at this time), so hosting externally on a commercial server is unfortunately not a solution.

So i'll tryout and test your suggestions and see if it helps any.

Thanks again!
Post Reply

Return to “Modules/Add-Ons”