We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30215
    • 79 Posts
    Is it too much when some of my pages need almost 110 mysql requests to load from cache (170 when load from database)?

    Problem is that I am building portal for local news and it contains a lot of subcategories (Ditto, ditto, ditto...) and also a lot of banners which need to be randomly changed for every page. I know that Ditto can be cached but I need some fields to be always updated (’how long is it since the article was published’). And random banners cannot be normaly cached for obvious reasons.

    How many requests is considered to be ’normal’?
      -- sorry for my english, bad teacher smiley
      • 30215
      • 79 Posts
      Hmm, I created simple log for storing mysql requests to check what is going on inside. For example I don’t understand why snippets are loaded from database everytime they are used. Only phx:phpthumb consumes 20 queries itself! Is it normal? Did I forget to change some settings?
        -- sorry for my english, bad teacher smiley
        • 22303 MODX Staff
        • 10,725 Posts
        Quote from: tobice at Jun 10, 2010, 05:16 PM

        Hmm, I created simple log for storing mysql requests to check what is going on inside. For example I don’t understand why snippets are loaded from database everytime they are used. Only phx:phpthumb consumes 20 queries itself! Is it normal? Did I forget to change some settings?
        What snippets are being loaded from the database? They are eval()’d from the siteCache.idx.php file. What version of MODx?

        Running Ditto uncached is not recommended, by me anyway.
          • 30215
          • 79 Posts
          SELECT snippet FROM `xsvoboda`.`x_site_snippets` WHERE `xsvoboda`.`x_site_snippets`.name='phx:phpthumb';
          SELECT snippet FROM `xsvoboda`.`x_site_snippets` WHERE `xsvoboda`.`x_site_snippets`.name='phx:cs_limit';
          SELECT snippet FROM `xsvoboda`.`x_site_snippets` WHERE `xsvoboda`.`x_site_snippets`.name='phx:phpthumb';
          SELECT snippet FROM `xsvoboda`.`x_site_snippets` WHERE `xsvoboda`.`x_site_snippets`.name='phx:cs_limit';
          SELECT snippet FROM `xsvoboda`.`x_site_snippets` WHERE `xsvoboda`.`x_site_snippets`.name='phx:phpthumb';
          SELECT snippet FROM `xsvoboda`.`x_site_snippets` WHERE `xsvoboda`.`x_site_snippets`.name='phx:cs_limit';


          It’s quite obvious that these snippets are being fetched again and again. I don’t know why cache doesn’t work in this case when caching docments is ok. I use include in both of these snippets. Does that matter?

          My modx version is 1.0.3, it’s quite recent.

          Thank you for quick reply:)
            -- sorry for my english, bad teacher smiley
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            That’s all coming from PHx. It doesn’t get its snippets from the cache file or from the existing MODx array of snippet code ($modx->snippetCache).
              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
              • 30215
              • 79 Posts
              It is weird that phx doesn’t use cache. However it is no longer a problem. I found a way how to keep the functionality and make Ditto cacheable. This reduced the number of requests to 13. 8 of it are my banners so the optimalization is now only up to my code smiley
                -- sorry for my english, bad teacher smiley
                • 36624
                • 535 Posts
                Quote from: tobice at Jun 11, 2010, 04:13 AM
                I found a way how to keep the functionality and make Ditto cacheable.
                can you explain how do you did optimize your page please ?
                  CTRL+SHIFT+U - Clear Cache
                  CTRL+SHIFT+H - Hiding Heft Panel
                  CTRL+SHIFT+N - Fast Create Resource
                  CTRL+ALT+P - Preview Recource (in edit resorce window)
                  CTRL+ALT+S - Save
                  • 22303 MODX Staff
                  • 10,725 Posts
                  Quote from: sottwell at Jun 11, 2010, 01:24 AM

                  That’s all coming from PHx. It doesn’t get its snippets from the cache file or from the existing MODx array of snippet code ($modx->snippetCache).
                  *blink*

                  I hope someone is addressing that, because of all places that need to use the cache, PHx is most definitely one.
                    • 30215
                    • 79 Posts
                    Quote from: manu at Jun 11, 2010, 06:54 AM

                    Quote from: tobice at Jun 11, 2010, 04:13 AM
                    I found a way how to keep the functionality and make Ditto cacheable.
                    can you explain how do you did optimize your page please ?

                    Actually, it wasn’t big deal after all smiley

                    My problem was that I wanted to display publish time not like a classical date but like the time which passed since the article was published (for example 3 minutes ago, 5 hours ago, two weeks ago etc). Logically it depends on current time and therefore this value must be counted every time when the page is opened. I wrote small snippet which worked great however I thought it wouldn’t work with Ditto cached. But then I read something about how the caching of snippets works and found out that it is not a problem. So I made Ditto cacheable ([! -> [[) and my snippet inside uncacheable and everything seems to be working fine.

                    Each Ditto call costs around ten sql requests (including those weird phx queries) and I use Ditto quite a lot. So finally I reduced the number of sql queries from 130 to 13. According to the time of processing, the page is now ten times faster smiley
                      -- sorry for my english, bad teacher smiley
                      • 5811
                      • 1,717 Posts
                      I created simple log for storing mysql requests to check what is going on inside.
                      How did you build this log ? by tracking the sql request in the modx->db api ?