Hi All,
I’m putting together a website that has a LOT of getResources calls - I’ve got 40+ resources (shows for a theatre) being pulled in to three separate divs on the page and now loads times are in excess of 15-30 seconds per page until cached.
I made a page with three snippets that run the getResources calls I need and output them to chunks, which I then call into my page. This has had a huge improvement on speed and now pages are 2-2.5 secs for first-run pages. The down side is I have to remember to run the ’processing’ page every time I add a new show. What I’d like to do is process the same getResources>chunk code when a page is saved to update stuff automatically. Using the same code as shown below as a plugin OnBeforeDocFormSave and OnDocFormSave.(code works fine when called as a snippet) I just get an empty value returned for $test (if I assign a value to $test it works). Any ideas if I can do this, or where I’m going wrong?
I’m not greatly technical but trying as best I can. Thanks in advance!
[tt]$test = $modx->runSnippet(’getResources’, array(
parents => ’56’,
tpl => ’gr-template’,
limit => ’0’,
depth => ’0’,
sortby => ’publishedon’
));
$chunk = $modx->getObject(’modChunk’, array(’name’ => ’output-chunk’));
if ($chunk) {
$chunk->setContent($test);
$chunk->save();
}[/tt]
Revo 2.0.8pl
-
MODX Staff
- 10,725 Posts
Are you using the latest version of getResources? It definitely should not take that long...especially if you are not including/processing TV values, doing TV filtering or sorting by TV values. Running the snippet in the manager as a plugin is not going to give you the proper results; we need to address and understand why this is taking so long to process...
Everything is up to date - but there IS a lot of TV processing, sorting and filtering going on with each show result - phpThumbOf creates a thumbnail of the show for example, and there are custom TV’s for dates and categories, also conditional checks for error checking with the IF snippet(eg if date provided then show date, else ’Date TBC’).
Isolating the most demanding getResources call by itself in an empty template takes over 3 seconds for 34 results - there another two similar large getResources calls on every page (the client wants an image carousel of all shows, plus a quick booking list of all shows). There are also several smaller getResources calls that call stuff like latest news results and special offers. I guess that’s a lot of processing per page that add up to a long time.
Do you think it be more efficient to write a custom snippet for the large calls than trying to use getResources for everything?
Thanks for your help.