We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36613
    • 328 Posts
    I have a website with 20 context and over 600 pages, and I saw the part of the front and is very slow. Analyzing the various snippts richimati I saw that this component:

    [[!getResources? 
    &parents=`99` 
    &tpl=`category-slider.myRowTpl` 
    &limit=`25`
    &includeTVs=`1`
    &includeTVList=`immagine-principale`
    &prepareTVList=`immagine-principale`
    &processTVList=`1`
    &context=`web` 
    ]]


    puts 3.5501 s for charging accordingly page is very slow.
    How do I optimize the various getResources pages?
      • 1343 ☆ A M B ☆
      • 2,213 Posts
      Hello,

      There are a few things you can do the first being cache the call (ex: [[getResources....]], so remove the !). You can also use getCache if the output isn't changed often, why rebuild when you can cache?

      The last suggestion off the top of my head is setting the depth (ex: &depth=`1`), if you don't need a huge depth this can be a big help.

      Give those a try first and let's go from there.
        Patrick | Server Wrangler
        About Me: Website | Tweets |  MODX Hosting
        • 36613
        • 328 Posts
        I can use GetCache but when the customer changes any page the cache is cleared and the website returns slowly.
          • 36613
          • 328 Posts
          It seems impossible for us to extract 25 results modx put 3.5501 seconds, is more faster a mysql query with php script sad
            • 1343 ☆ A M B ☆
            • 2,213 Posts
            Hello,

            Did you try my other suggestions, and if so what was the end result? Also could you share the contents of the tpl being used?
              Patrick | Server Wrangler
              About Me: Website | Tweets |  MODX Hosting
              • 9207 ☆ A M B ☆
              • 2,475 Posts
              If getResources is proving to be too slow, try writing your own Snippet that issues its own database query and then cache the results of that Snippet. Accessing TVs is especially slow because it's hard for the database to "turn corners" when it's trying to run fast.

                • 9102 ☆ A M B ☆
                • 318 Posts
                The other thing to look at is the content of the template - could you post that? If it has conditional logic, output filters, nested chunks etc. it might be possible to rewrite it to run a lot faster.

                Also, the whole point of getCache is that it allows you to partition the cache so that the cache for a particular set of snippet calls is not cleared when the main cache is cleared (by changing pages etc.) the downside of this is that if you make a change that affects the output of the snippet call, you have to remember to clear the appropriate cache partition - but you can set up a menu option to easily do that. See this blog post: http://modx.com/blog/2012/10/29/optimization-with-getcache-and-custom-cache-partitions/
                  • 36613
                  • 328 Posts
                  This is an example of the template estrare products in a given category:
                  <!DOCTYPE html>
                  <!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7 ie"><![endif]-->
                  <!--[if IE 7]><html class="no-js lt-ie9 lt-ie8 ie"><![endif]-->
                  <!--[if IE 8]><html class="no-js lt-ie9 ie"><![endif]-->
                  <!--[if gt IE 8]><!--><html class="no-js"><!--<![endif]-->
                      <head>
                  
                          <meta charset="utf-8">
                          <title>[[*pagetitle]]</title>
                          <meta name="keywords" content="[[*keywords]]" />
                          <meta name="description" content="[[*description]]" />
                          <base href="[[!++site_url]]" />
                          
                        
                          <link rel="stylesheet" href="[[++site_url]]assets/templates/default/css/reset.css">
                          <link rel="stylesheet" href="[[++site_url]]assets/templates/default/css/normalize.min.css">
                          <link rel="stylesheet" href="[[++site_url]]assets/templates/default/css/base.css">
                          <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css">
                         <link rel='stylesheet' href='http://fonts.googleapis.com/css?family=Passion+One:400,700|Ubuntu:400,400italic,700,500,500italic,700italic'>
                          <link rel="stylesheet" href="[[++site_url]]assets/templates/default/css/layout.css">
                  
                          <!--[if lt IE 9]>
                              <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
                              <script src="[[++site_url]]assets/templates/default/js/vendor/html5-3.6-respond-1.1.0.min.js"></script>
                          <![endif]-->
                  
                          <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
                          <script>window.jQuery || document.write('<script src="[[++site_url]]assets/templates/default/js/vendor/jquery-1.9.1.min.js"><\/script>')</script>
                          <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
                          <script src="[[++site_url]]assets/templates/default/addons/flexslider-2.1/jquery.flexslider-min.js"></script>
                          <script src="[[++site_url]]assets/templates/default/js/jquery.placeholder.min.js"></script>
                          <script src="[[++site_url]]assets/templates/default/js/main.js"></script>
                  
                  
                  
                          <link rel="stylesheet" href="[[++site_url]]assets/templates/default/css/default.css">
                  
                  
                          [[*webdeveloper-css]]
                          [[*webdeveloper-js]]
                  
                  
                      </head>
                      <body>
                          <!--[if lt IE 7]>
                          <p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
                      <![endif]-->
                  
                  
                          <!-- Primary Page Layout
                          ================================================== -->
                          <div class="container">
                              <header class="primary row">
                  <div class="four columns">
                      <div id="site-title"><a href="[[~1]]">Logo</a></div>
                  </div>
                  <div class="eight columns">
                      <nav class="utility">
                          <ul><li>test...</li></ul>
                      </nav>
                  </div>
                  <div class="four columns">
                      <div id="searchform">
                          [[!SimpleSearchForm? &landing=`128` &tpl=`MySearchForm` &searchIndex=`search`]]
                      </div>
                      <div id="facebook"><a href="https://www.facebook.com/" target="_blank">Facebook</a></div>
                  </div>
                  </header>
                  <nav class="primary row">
                  <div class="sixteen columns clearfix">
                  
                  <ul>
                  
                  [[!getCache@myGetResourcesPropertySet?
                  &element=`Wayfinder`
                  &cacheKey=`menu_getCache`
                  &startId=`0`
                  &level=`2` 
                  &excludeDocs=`1,63,64,65,66,67,68` 
                  &rowTpl=`menudinavigazione-primaria.rowTpl` 
                  &innerTpl=`menudinavigazione-primaria.innerTpl` 
                  &innerRowTpl=`menudinavigazione-primaria.innerRowTpl` 
                  &levelClass=`level`
                  &where=`{"isfolder":1}`  ]]
                  
                  </ul>
                  
                  </div>
                  </nav>
                             
                              <section id="breadcrumbs" class="clearfix">
                                  <div class="sixteen columns breadcrumbs">
                                      [[$breadcrumbs]]
                                  </div>
                              </section>
                              <section id="presentation" class="row">
                                  <div class="eleven columns">[[*immagine-principale:notempty=`<img id="presentation-img" src="[[*immagine-principale]]">`]]</div>
                                  <div class="five columns" id="presentation-text">
                                      [[*pagetitle:notempty=`<h1>[[*pagetitle]]</h1>`]]
                                      [[*content]]
                                      <!-- AddThis Button BEGIN -->
                                      <div class="addthis_toolbox addthis_default_style ">
                                          <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
                                          <a class="addthis_button_tweet"></a>
                                          <a class="addthis_button_pinterest_pinit"></a>
                                          
                                      </div>
                                      <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=xa-518a217669a964f6"></script>
                                      <!-- AddThis Button END -->
                                  </div>
                              </section>
                              <section id="main" class="row">
                                  <div class="columns" >
                  <div class="row">
                  [[!getCache@myGetResourcesPropertySet?
                  &element=`getResources`
                  &cacheKey=`prodotti_getCache`
                  &cacheExpires=`0`
                  &parents=`[[*id]]`
                  &limit=`0`
                  &depth=`0`
                  &tpl=`Categoria.myRowTpl`
                  &includeTVs=`1`
                  &includeTVs=`1`
                  &includeTVList=`immagine-principale`
                  &prepareTVList=`immagine-principale`
                  &processTVList=`1`
                  ]]
                  </div>
                                  </div>
                                  <div class="five columns" id="catalogue">
                                 [[$ContactForm]]
                  
                  
                                  </div>
                              </section>
                  
                  [[$footer]]
                  
                          </div><!-- cont -->
                      </body>
                  </html>
                    • 36613
                    • 328 Posts
                    This is an example of a page template text base with side menu:

                    <!--same head of categories -->
                        </head>
                        <body>
                    
                    
                    
                            <div class="container">
                                  <header class="primary">
                    <div class=" columns">
                        <div id="site-title"><a href="[[~1]]">Logo</a></div>
                    </div>
                    <div class="eight columns">
                        <nav class="utility">
                            <ul><li>test...</li></ul>
                        </nav>
                    </div>
                    <div class="four columns">
                        <div id="searchform">
                            [[!SimpleSearchForm? &landing=`128` &tpl=`MySearchForm` &searchIndex=`search`]]
                        </div>
                        <div id="facebook"><a href="https://www.facebook.com/" target="_blank">Facebook</a></div>
                    </div>
                    </header>
                    <nav class="primary row">
                    <div class="sixteen columns clearfix">
                    
                    <ul>
                    
                    [[!getCache@myGetResourcesPropertySet?
                    &element=`Wayfinder`
                    &cacheKey=`menu_getCache`
                    &startId=`0`
                    &level=`2` 
                    &excludeDocs=`1,63,64,65,66,67,68` 
                    &rowTpl=`menudinavigazione-primaria.rowTpl` 
                    &innerTpl=`menudinavigazione-primaria.innerTpl` 
                    &innerRowTpl=`menudinavigazione-primaria.innerRowTpl` 
                    &levelClass=`level`
                    &where=`{"isfolder":1}`  ]]
                    
                    </ul>
                    
                    </div>
                    </nav>
                    
                                <section id="main" class="row">
                                    <div class="four columns">
                                    <nav class="secondary">
                    [[Wayfinder?  
                    &startId=`[[UltimateParent]]` 
                    &displayStart=`1`
                    &outerTpl=`menudinavigazione-secondaria-slpt.outerTpl`  
                    &rowTpl=`menudinavigazione-secondaria-slpt.rowTpl`  
                    &innerRowTpl=`menudinavigazione-secondaria-slpt.innerRowTpl` 
                    &startItemTpl=`menudinavigazione-secondaria-slpt.startItemTpl` 
                    &level=`2`
                    ]]
                    </nav>
                    
                    <ul id="static-linking">
                        <li>
                         <a class="spot-link" href="[[getCrossLink? &id=`68`]]">Contattaci</a>
                        </li>
                        <li>
                         <a class="spot-link" href="[[getCrossLink? &id=`180`]]">More Info</a>
                        </li>
                    </ul>
                     
                                    </div>
                                    <div class="twelve columns offset-by-one">   
                                         <div class="breadcrumbs">
                                        [[$breadcrumbs]]
                                        </div>
                                        [[*pagetitle:notempty=`<h1>[[*pagetitle]]</h1>`]]
                                        <div id="base1" >
                                            [[*content]]
                                            [[!If? &subject=`[[*GalleryAlbum]]` &operator=`!empty` &then=`[[$prettyGallery]]`]]
                                        </div>
                                        
                                    </div>
                                </section>
                                
                    [[$footer]]
                    
                    [[!If? &subject=`[[*GalleryAlbum]]` &operator=`!empty` &then=`[[$prettyGalleryScripts]]`]]
                    
                            </div>
                        </body>
                    </html>
                      • 36613
                      • 328 Posts
                      As I have said I used GetCache and actually the category page seems faster.
                      However, if the customer add a product category return slow.
                      Furthermore, the second page, which I called baste text, not the call to getResouces
                      still has two menus for the horizontal and the vertical and horizontal menu of admitting GetCache can use:


                      [[!getCache@myGetResourcesPropertySet?
                      &element=`Wayfinder`
                      &cacheKey=`menu_getCache`
                      &startId=`0`
                      &level=`2`
                      &excludeDocs=`1,63,64,65,66,67,68`
                      &rowTpl=`menudinavigazione-primaria.rowTpl`
                      &innerTpl=`menudinavigazione-primaria.innerTpl`
                      &innerRowTpl=`menudinavigazione-primaria.innerRowTpl`
                      &levelClass=`level`
                      &where=`{"isfolder":1}`  ]]




                      In the vertical menu I can not use:

                      [[Wayfinder? 
                      &startId=`[[UltimateParent]]`
                      &displayStart=`1`
                      &outerTpl=`menudinavigazione-secondaria-slpt.outerTpl` 
                      &rowTpl=`menudinavigazione-secondaria-slpt.rowTpl` 
                      &innerRowTpl=`menudinavigazione-secondaria-slpt.innerRowTpl`
                      &startItemTpl=`menudinavigazione-secondaria-slpt.startItemTpl`
                      &level=`2`
                      ]]


                      Because otherwise my client every time you change a page should remember to clear
                      the cache and the vertical menu.
                      Even the base template text, however, is slow.