We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33337
    • 3,975 Posts
    An idea clicks in my mind is, use the wayfinder menu in a separate document as a content and call it in a TV with @Binding

    OR

    use getField? snippet to call the doc content.

    Ofcourse be sure to keep that doc cached, and untick the "Empty cache?" check box to prevent cache clearing automatically.

    Hope you got my point...
      Zaigham R - MODX Professional | Skype | Email | Twitter

      Digging the interwebs for #MODX gems and bringing it to you. modx.link
      • 4310
      • 2,310 Posts
      IMHO it seems that you’re duplicating the menu for the second, third and fourth level items in the left column depending which page you are visiting.
      Could you not have a level 1 top menu and the side menu for levels 2,3 & 4 of the parent page?
      This might speed up the page loading.

      David
        • 10449
        • 956 Posts
        I don’t think any amount of items should slow the site down as much as your example shows.
        Even your "fast" loading site (about 3 seconds) is really slow. I think it’s simply a rather slow database connection.
        The fact that you’re including so many items with your WF call certainly doesn’t speed things up.

        But yes, you can of course store the Wayfinder output to a static file and include that in your template. Instead of a file you can use a chunk, or even a new document.
        Just make sure the editors remember to update this chunk. You could also write a little plugin that updates your menu-chunk every time a document is created or changed. The system event would probably be OnDocFormSave. Useful API functions would be http://wiki.modxcms.com/index.php/API:runSnippet + http://wiki.modxcms.com/index.php/API:getChunk. I wonder if there’s a setChunk() / saveChunk() available too...
        hmm, just found out there is apparently a putChunk() function available, though it’s not documented in the Wiki...

        I believe items that don’t change frequently shouldn’t necessarily be called via database-calls. e.g. generating an XML file via PHP + mxSQL on every new request is not as efficient as storing a file on the server and just let Apache serve it as a regular text-file.
          • 13481
          • 97 Posts
          Quote from: bunk58 at Jan 28, 2008, 04:04 PM

          IMHO it seems that you’re duplicating the menu for the second, third and fourth level items in the left column depending which page you are visiting.
          Could you not have a level 1 top menu and the side menu for levels 2,3 & 4 of the parent page?
          This might speed up the page loading.

          David


          I agree with you, this was a client request that we couldn’t talk them out of.

          Quote from: ganeshXL at Jan 28, 2008, 04:12 PM

          I don’t think any amount of items should slow the site down as much as your example shows.
          Even your "fast" loading site (about 3 seconds) is really slow. I think it’s simply a rather slow database connection.
          The fact that you’re including so many items with your WF call certainly doesn’t speed things up.

          But yes, you can of course store the Wayfinder output to a static file and include that in your template. Instead of a file you can use a chunk, or even a new document.
          Just make sure the editors remember to update this chunk. You could also write a little plugin that updates your menu-chunk every time a document is created or changed. The system event would probably be OnDocFormSave. Useful API functions would be http://wiki.modxcms.com/index.php/API:runSnippet + http://wiki.modxcms.com/index.php/API:getChunk. I wonder if there’s a setChunk() / saveChunk() available too...
          hmm, just found out there is apparently a putChunk() function available, though it’s not documented in the Wiki...

          I believe items that don’t change frequently shouldn’t necessarily be called via database-calls. e.g. generating an XML file via PHP + mxSQL on every new request is not as efficient as storing a file on the server and just let Apache serve it as a regular text-file.

          As I write more on this post I think what you wrote or some variation of it will be what I have to do.

          I’m not a server admin, and this is the first time I’ve worked on a production MAMP environment, so that certainly hasn’t helped me out. I’ve wondered about the database being slow. I know it is not caching queries, but I can’t figure out how to turn that on. The database is on the same server and is only used for MODx so it shouldn’t be this slow.

          Thanks for all of your help and keep the ideas coming if you’ve got more.

          James
            • 10449
            • 956 Posts
            OK, I just tried this, and it works fine here:

            a) create a chunk. Leave it empty. Name it whatever you want, e.g. testMenu

            b) create a plugin. Enter this:
            $myChunk = 'testMenu'; // your chunk name
            $params['startId'] = '0';
            $params['level'] = '4';
            $html = addslashes($modx->runSnippet('Wayfinder', $params));
            $sql= "UPDATE " . $modx->getFullTableName("site_htmlsnippets") . " SET snippet='$html' WHERE name='$myChunk'";
            $result= $modx->dbQuery($sql);
            


            c) Check the system event OnDocFormSave + save the plugin.

            d) Change your template: Replace your Wayfinder call with your chunk: {{testMenu}}

            Now, every time you edit a doc, the Menu code is being regenerated and stored in your chunk. This should speed up things quite a bit...
            • So to make this perfectly clear, using this method the menu is generated only when a document is saved, not at every page request. This would also work with Ditto, wouldn’t it?
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 10449
                • 956 Posts
                Yes. It would work with every snippet, I assume. I’ve only had time to test it with Wayfinder, but I don’t see why it should be impossible with Ditto.

                Another real-life example would be RSS-feeds: Instead of generating the RSS output on every frontend request, you would only update the chunk if docs are added/changed.

                An approach with static files would just need to replace the sql update funcs with something like:

                $fh = fopen(’path/to/static/menu.html’, ’w’) or die("can’t open file");
                fwrite($fh, $html);
                fclose($fh);

                And in your template or doc, you’d simply include it via snippet or TV with @FILE binding.

                For really small sites with little content or low traffic you wouldn’t notice any difference, but for heavily used sites with tons of pages and several snippets per page etc. I believe this might help.
                  • 4310
                  • 2,310 Posts
                  What a great idea to reduce server load. grin
                  Just tried it with Wayfinder, it included some docs that were restricted to logged in web users.
                  Tried adding some extra parameters such as
                  $params['parentRowTpl'] = 'newMenu';
                  $params['cssTpl'] = 'newMenuCSS';

                  The parentRowTPL worked, but the add css file wasn’t added to the page. (works in the original Wayfinder call)
                  I appreciate this was a quick look at solving the issue and I’m only giving constructive feedback.

                  David
                    • 13481
                    • 97 Posts
                    ganeshXL - you rock. Thanks for the code!
                      • 10449
                      • 956 Posts
                      @bunk58: I believe that’s because the way this parameter is treated, is to inject your CSS stuff in the head section of the document that loads the Wayfinder call.
                      If no document is available at the time this snippet runs (i.e. just a chunk), then WF probably doesn’t know where or how to add this extra CSS.

                      "The cssTpl allows for a chunk containing a link to a style sheet or style information to be inserted into the head section of the generated page."
                      -> http://www.muddydogpaws.com/development/wayfinder/parameters.html
                      The same thing probably happens with a jsTpl.

                      A workaround for such instances is to just simply add those extra bits of JS + CSS in your template.


                      @devtrench: Thanks smiley