We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50923
    • 137 Posts
    I ahve very complex getResources call, it is possible that someone help me to speed it up?

    [[!getResources? &resources=`-[[!UltimateParent]],-[[*id]],[[!getPagesbyTerm? &term_id=`[[!MainCategory? &values=`[[!getPageTerms? &outerTpl=`` &innerTpl=`AllCategoryIds` &limit=`0`]]`]]` &innerTpl=`AllOffersIds` &limit=`0` &outerTpl=``]]` &tpl=`RecommendOffersTpl` &limit=`3` &includeTVs=`1` &processTVs=`1` &tvPrefix=`` &hideContainers=`1` &sortby=`RAND()` &showHidden=`1`]] 
      <a href="www.play2web.com" title="izrada web sajtova">Izrada web sajtova</a>
      • 20413
      • 2,877 Posts
      1. Write it out readable! smiley

      [[!getResources? 
      	&resources=`
      				-[[!UltimateParent]],
      				-[[*id]],
      				 [[!getPagesbyTerm? 
      				 	&term_id=`[[!MainCategory? 
      							  		&values=`[[!getPageTerms? 
      												&outerTpl=`` 
      												&innerTpl=`AllCategoryIds` 
      												&limit=`0`
      											 ]]`
      							  ]]` 
      					&innerTpl=`AllOffersIds` 
      					&limit=`0` 
      					&outerTpl=``
      				 ]]` 
      	&tpl=`RecommendOffersTpl` 
      	&limit=`3` 
      	&includeTVs=`1` 
      	&processTVs=`1` 
      	&tvPrefix=`` 
      	&hideContainers=`1` 
      	&sortby=`RAND()` 
      	&showHidden=`1`
      ]]
      


      2. The &resources values could be converted into one snippet.

      3. PDOTools is faster! http://modx.today/posts/2016/04/pdotools-introduction-(part-2) <--- Copy and paste the url
        @hawproductions | http://mrhaw.com/

        Infograph: MODX Advanced Install in 7 steps:
        http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

        Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
        http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
        • 3749
        • 24,544 Posts
        This seems crazy to me:

        -[[!UltimateParent]],
        [[!getPagesbyTerm? 
           &term_id=`[[!MainCategory? 
               &values=`[[!getPageTerms? 
                    &outerTpl=`` 
                    &innerTpl=`AllCategoryIds` 
                    &limit=`0`
              ]]`
           ]]` 
           &innerTpl=`AllOffersIds` 
           &limit=`0` 
           &outerTpl=``
        ]]` 


        You're running four separate snippets (six, if you count the two that are created inside the two pageTerms snippets), loading an autoloader, and making a number of separate queries to the DB just to get a list of IDs for getResources to retrieve (or not retrieve).

        I'm not that familiar with Taxonomies, but it looks like both getPagesbyTerm and getPageTerms are both meant to display resources (since they have Tpls), but you're not using them for that, so they're kind of overkill for your use case.

        I would rewrite the whole thing as a custom snippet (or at least the &resources part as mrhaw suggests) to merge the many snippets you're running into a single snippet using parts of the code from the various snippets being called.

        If you're not up to that, using pdoResources (from the pdoTools package) would definitely speed things up.

        If you can use the raw values of your TVs, you don't need &processTVs.

        If only some of the TVs need to be processed, you can use &prepareTVList to list them.

        If you're not using all the TVs from the pages, you can use &includeTVList to designate the ones you're using.

        If you can hard-code the UltimateParent's returned value that will also speed things up.

        As a last resort, you can go through the pages and hard-code the comma-separated list of IDs in the &resources property if that would work for you.
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 40706
          • 128 Posts
          Cache as much as Possible.

          For example [[!UltimateParent]], its impossible to change the UltimateParent, when not saving or moving an Document in the manager, which results an cache refresh. getPageTerms seams also be not needed to called uncached.
          Call everything cached, which can only change on manager saves!

          When you are querying for that detailed data, its much more speedy to do this in an custom-Snippet.