Loading...
 
Skip to main content

Copied from MR85 for Tiki 20

Sometimes we have a lot of LIST plugins on one page, especially if they are nested you are going to have a lot in total. If each one makes their own connections to the ES server, it very quickly adds up to a lot of connections and results in slow performance.
To get around this, one way is to make use of Elasticsearch's multisearch feature to bundle all of the queries from different LIST plugins to query all at one go at the "top of the page", but instead of rendering the output, we save the results sent back from ES for rendering further down the page. Our tests show a significant improvement in performance, e.g. a page that took 4 sec to load can now only take 2 sec.
To implement this, you need to add a LIST plugin at the top of your output template (whether wiki page template or Smarty template) that uses {MULTISEARCH(id=x)}...{MULTISEARCH} blocks to contain the queries to bundle. Then you have your LIST plugins as usual for rendering the search results, but set multisearchid=x as a parameter for the LIST plugin. This instructs it to retrieve and format the search results that have already been returned, rather than to conduct it's own search.
Here is an example. Imagine you have a page that loads themes, say 20 of them, and for each of them you show the 4 latest created resources from that theme.
The "top" list plugin like this:

Example wiki page
Copy to clipboard
{LIST()} {filter type="trackeritem"} {filter field="tracker_id" exact="5"} {sort mode="tracker_field_order_asc"} {output template="resources-theme-results.tpl" result=$results} {LIST}

Example resources-theme-results.tpl output template file
Copy to clipboard
{wikiplugin _name=list} {foreach $results as $result} {literal} {MULTISEARCH(id="{/literal}resources-{$result@key}{literal}")} {pagination max=4} {filter type="trackeritem"} {filter field="tracker_id" exact="7"} {filter field="tracker_field_resourceTheme" multivalue="{/literal}{$result.tracker_field_themeCategory_text}{literal}"} {sort mode="creation_date_desc"} {MULTISEARCH} {/literal} {/foreach} {/wikiplugin} {foreach $results as $result} <div class="row"> <div class="resource-item-container" id="theme-{$result.tracker_field_themeCategory_text}"> <div class="resource-header clearfix"> <a href="resources-by-theme?theme_id={$result.tracker_field_themeCategory_text}"> <h4 class="pull-left"> {$result.tracker_field_name} </h4> </a> <a href="resources-by-theme?theme_id={$result.tracker_field_themeCategory_text}" class="pull-right view-all">View all ></a> </div> <div class="resource-results card-container card-container-col-4"> {wikiplugin _name=list multisearchid="resources-{$result@key}"} {literal} {pagination max=4} {filter type="trackeritem"} {filter field="tracker_id" exact="7"} {filter field="tracker_field_resourceTheme" multivalue="{/literal}{$result.tracker_field_themeCategory_text}{literal}"} {sort mode="creation_date_desc"} {output template="resources-results.tpl"} {ALTERNATE()} <div class="resource-results" style="margin-left:10px;" No resources under this theme yet. </div> {ALTERNATE} {/literal} {/wikiplugin} </div> </div> </div> {/foreach}

All the LIST Plugin control blocks