We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37126
    • 37 Posts
    So I've been making the snippets and chunks more efficient on the site I'm working on but these response times are silly. Where else should I look to improve things? I've added xFPC which is great once pages are cached but it seems like the wrong approach. The site is on a CPanel package on hostgator.

    MySQL: 0.0001 s s, 1 request(s), PHP: 10.7274 s s, total: 10.7275 s s, document retrieved from database.

    MySQL: 0.0000 s s, 1 request(s), PHP: 18.1852 s s, total: 18.1852 s s, document retrieved from database.

    This last one is a page containing 53 thumbnails that are converted from pdfs
    MySQL: 0.0005 s s, 2 request(s), PHP: 250.2119 s s, total: 250.2124 s s, document retrieved from database.
      • 22840
      • 1,572 Posts
      What calls do you have on the page ?, IE: getresources, wayfinder ?
        • 37126
        • 37 Posts
        Here's most of the call on a typical page, quite a long list. The templates are shared across three contexts hence lots of conditionals.

        [[*template:is=`9`
        :then=`
        <script type="text/javascript">
        var avl = {}
        avl.multi = [{[[getImageList?&tvname=`npt.multidest`&tpl=`npt.avail`]]}]
        avl.singl = [{[[getImageList?&tvname=`npt.singledest`&tpl=`npt.avail`]]}]
        avl.jnr = [{[[getImageList?&tvname=`npt.jnr.multidest`&tpl=`npt.avail`]]}]
        avl.jfull = [{[[getImageList?&tvname=`npt.jnr.full`&tpl=`npt.jf.avail`]]}]
        </script>
        `]]
        [[*template:is=`6`
        :then=`<script type="text/javascript">
        var gblocks = 
        [[*dest.gridblock]]
        </script>
        `]]
        [[*template:is=`22`:then=`<script type="text/javascript">
        var gblocks = [
        [*dest.gridblock]]
        </script>`]]
        [[*template:is=`16`:then=`<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA_focqBYhZJtlLvqQipSskz3CHclSimrA&sensor=false"></script>`]]
        
        
        [[[[!*context_key:eq=`site2`:then=`$callbackUK`:else=`$callback`]]]]
        
        Top navigation
        [[Wayfinder? &startId=`0` &level=`10` &levelClass=`level` &firstClass=`parent` &hereClass=`current` &rowIdPrefix=`1` &rowTpl=`MXrow` &innerTpl=`MXinner`]]
        
        In top navigation row tpl
        <li class="[[+wf.classnames]][[+showFlag:is=`1`:and:[[+FlagSelector]]:isnot=``:then=` [[+FlagSelector]]`]]"><a href="[[+wf.link]]"[[+wf.classes]]>[[+wf.linktext]]</a>[[+wf.wrapper]]</li>
        
        In side navigation
        [[Wayfinder? &startId=`0` &outerClass=`lh_nav` &rowTpl=`sideRowF` &hideSubMenus=`true`]]
        
        In side navigation row Tpl
        <li class="[[+wf.classnames]][[+showFlag:is=`1`:and:[[+FlagSelector]]:isnot=``:then=` [[+FlagSelector]]`]]corner"><a href="[[+wf.link]]"[[+wf.classes]] title="[[+wf.pagetitle]]">[[+wf.linktext]]</a>[[+wf.wrapper]]</li>
        
        [[!*context_key:eq=`site2`:then=`<strong>Destinations: </strong>`:else=`<strong>Destinazioni: </strong>`]]</p>
        <div class="coursesummary">
        
        [[*course.image:ne=``:then=`<div class="courseimgsoc">[[$courseDetailImg]][[$socialLinks]]</div>`:else=`[[$socialLinks]]`]]
        
        [[*context_key:eq=`site2`:then=`<a href="[[++site_url]]book-form-uk?c=[[*id]]" class="button">Book</a>`:else=`<a href="[[++site_url]]book-form?c=[[*id]]" class="button">subito</a>`]]
        
        [[*context_key:eq=`site2`:then=`Call`:else=`Chiamiamo`]]
        
        [[*context_key:eq=`site2`:then=`<a href="[[++site_url]]mail-uk?c=[[*id]]" class="button">Contact us</a>`:else=`<a href="[[++site_url]]mail?c=[[*id]]" class="button">Mail</a>`]]
        
        [[[[*DocList:gt=``:then=`getImageList? &tvname=`DocList` &tpl=`showdocs``]]]]
        
        [[[[*course.moreinfo:notempty=`$furtherinfoimg`]]]]				
        
        [[!*context_key:eq=`site2`
        :then=`
        [[getResourceField? &id=`210` &field=`testimonial.header` &processTV=`1`]]</h3>
        <blockquote>[[getResourceField? &id=`210` &field=`testimonial.quote` &processTV=`1`]]
        [[getResourceField? &id=`210` &field=`testimonial.cite` &processTV=`1`]]
        [[getResourceField? &id=`210` &field=`contact.header` &processTV=`1`]]
        [[getResourceField? &id=`210` &field=`contact.address` &processTV=`1`]]
        </div>`
        :else=`
        [[getResourceField? &id=`12` &field=`testimonial.header` &processTV=`1`]]
        [[getResourceField? &id=`12` &field=`testimonial.quote` &processTV=`1`]]
        [[getResourceField? &id=`12` &field=`testimonial.cite` &processTV=`1`]]
        [[getResourceField? &id=`12` &field=`contact.header` &processTV=`1`]]
        [[getResourceField? &id=`12` &field=`contact.address` &processTV=`1`]]
        `]]
        
        [[!*context_key:eq=`web`:then=`[[Wayfinder? &startId=`174` &level=`1` &outerTpl=`legalOuter` &ignoreHidden=`1`]]`:else=``]]
        
        [[!*context_key:eq=`site2`:then=`[[Wayfinder? &startId=`329` &level=`1` &outerTpl=`legalOuterML` &ignoreHidden=`1`]]`:else=``]]
        
        [[!*context_key:eq=`site3`:then=`[[Wayfinder? &startId=`478` &level=`1` &outerTpl=`legalOuter` &ignoreHidden=`1`]]`:else=``]]
        
          • 22303 MODX Staff
          • 10,725 Posts
          I would read this — http://modx.com/blog/2012/09/14/tags-as-the-result-or-how-conditionals-are-like-mosquitoes/ and then reconsider how you are creating your Templates. As is, you are processing everything in each conditional result, regardless of the conditional evaluation.
            • 37126
            • 37 Posts
            Thanks Jason,
            I've tried to follow the recommendations. I've worked out what is causing the issue and that's the Wayfinder Call. The site uses a mega menu which contains around 100 or so links and some of the links have a placeholder which displays a flag. This is the call:

            Wayfinder call
            <nav id="section">
            [[Wayfinder?
            &startId=`0`
            &level=`4`
            &levelClass=`level`
            &firstClass=`parent`
            &hereClass=`current`
            &rowIdPrefix=`1`
            &rowTpl=`MXrow`
            &innerTpl=`MXinner`
            ]]
            </nav>


            MXinner
            <ul class="inner">
            [[+wf.wrapper]]
            </ul>


            MXrow
            <li class="[[+wf.classnames]][[+showFlag:is=`1`:and:[[+FlagSelector]]:isnot=``:then=` [[+FlagSelector]]`]]"><a href="[[+wf.link]]"[[+wf.classes]]>[[+wf.linktext]]</a>[[+wf.wrapper]]</li>


            FlagSelector is a tv that chooses a country from a drop down and showFlag a checkbox TV to display a flag or not.

            I've seen a thread earlier from Mark Hamstra and Bob on how to cache the wayfinder call site wide but I'm not sure how to implement it site wide and whether as the templates are shared across contexts whether this would still work.

            https://forums.modx.com/thread/73328/wayfinder-performance

            Or would &cacheResults=`1` make any difference

            I just hope there's a way to do it and keep the flags which seem to really slow things down they are around 1k each and used as background images but it's this bit that's slowing things down
            [[+showFlag:is=`1`:and:[[+FlagSelector]]:isnot=``:then=` [[+FlagSelector]]`]]
              • 37126
              • 37 Posts
              So I'm using this snippet for the flag placeholder in wayfinder now which seems to shave a bit of load time off. Is this a more efficient call than an output modifier?

              getflag snippet
              <?php
              $doc = $modx->getObject('modResource', $select);
              $flag = $doc->getTVValue($myTV);
              $show = $doc->getTVValue($myTV2);
              
              if ($show == 1) {
                   return $flag;
              }


              Row Tpl
              <li class="[[+wf.classnames]] [[getflag? &select=`[[+id]]` &myTV=`FlagSelector` &myTV2=`showFlag`]]"><a href="[[+wf.link]]"[[+wf.classes]]>[[+wf.linktext]]</a>[[+wf.wrapper]]</li>