Page 1 of 1

LISE - Very slow template/output

Posted: Fri Aug 11, 2023 10:33 am
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.

Re: LISE - Very slow template/output

Posted: Fri Aug 11, 2023 12:03 pm
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.

Re: LISE - Very slow template/output

Posted: Fri Aug 11, 2023 12:49 pm
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.

Re: LISE - Very slow template/output

Posted: Mon Aug 21, 2023 10:15 am
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

Re: LISE - Very slow template/output

Posted: Mon Aug 21, 2023 11:11 am
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.

Re: LISE - Very slow template/output

Posted: Wed Aug 23, 2023 8:09 am
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!