We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36837
    • 9 Posts
    Quote from: esnyder at Dec 09, 2011, 05:19 PM
    You can speed up the uncached performance of getResources quite a bit by using the includeTVList and processTVList parameters to limit it to just looking at the TVs you want. Since you're not processing TVs anyway the latter doesn't apply in this case but I thought I'd mention it for others.
    Performance is still not ideal but it should be quite a bit better.

    Oh yeah it's great! But there are some features.

    1. If you use only one TV image without handlers (eg phpThumb) and only one parameter, such as (& includeTVList = `smallThumbnail`) it works almost perfectly. PHP 0,95 sec vs 3.57 sec (first load with a clean cache):
    <img src="[[+tv.smallThumbnail]]">
    
    [[!getResources?
    &hideContainers=`1`
    &sortby=`{"createdon":"DESC"}`
    &parents=`11`
    &showHidden=`1`
    &tpl=`homeGallItem`
    &limit=`10`
    &includeTVs=`1`
    &includeTVList=`smallThumbnail`
    &depth=`2`
    

    2. If you use a single parameter, but with handlers, the rate increases, but not so much: 1,9 sec vs 3.57 sec
    <img src="[[+tv.bigImg:phpthumbof=`w=350&h=150&zc=1`]]">

    3. But in my case I use a more complex output chunk:
    <img src="[[+tv.smallThumbnail:empty=`[[+tv.bigImg:phpthumbof=`w=350&h=150&zc=1`]]`]]" width="350" height="150" alt="[[+pagetitle]]">

    In this case, I should use this code here:
    &includeTVList=`smallThumbnail,bigImg`

    At the same time I almost did not notice the acceleration. Perhaps none at all.
    However, I do not understand how to use these options:
    &processTVs=`1`
    &processTVList=`smallThumbnail,bigImg`

    With them or without them, the result remains the same.

    By the way, is there a more optimal way to display the TV image? [ed. note: dgbomb last edited this post 14 years, 10 months ago.]
      • 3749
      • 24,544 Posts
      Quote from: sottwell at Dec 09, 2011, 01:54 AM
      One way you can minimize this is to consider what pages won't affect dynamic things such as generated menus or news listings, and set those resources settings to not clear the cache on save.

      Unless you're talking about 2.2, I don't think that will help. As far as I can tell, that's not a permanent setting (there's no field for it in the DB). It's reset to not clear the cache every time you edit the resource. And if you uncheck the box, it fails to update the cache for that resource when you save it, so I've never understood the point of it.

      I guess it would make sense to use it if the resource is not cacheable and you want to save a new version without clearing the rest of the cache.

      What we really need is a way to regenerate the cache when we finish working on the site so it will be up to speed for visitors. Maybe that's an option in 2.2 -- I have yet to test it.
        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
        • 9102 ☆ A M B ☆
        • 318 Posts
        Phpthumbof tends to be slow uncached. You may be able to improve that by turning off the phpThumbOfCacheManager plugin, which clears your cache folder every time you clear the cache. That means every time you clear the cache you have to regenerate your thumbnails, which can be pretty slow especially if the original image is big. So if you don't clear the cache folder when clearing the site cache, the thumbnails are still there and phpThumbOf doesn't have to regenerate them.

        I don't think you need to render your TVs to use output filters. They're basically just snippets, just feed them the raw TV. However, using nested snippets inside getResources will slow it down a lot for sure. I think your uncached performance is unlikely to get much better with this setup.

        I use Amazon S3 and have a lot of thumbnails. I use getPage and getResources and lots of nested snippet calls because I'm doing fancy things with my thumbs. Uncached, my pages take about 5 sec to render -- that's with every optimization I can think of, and it's a huge improvement over not using the includeTVList parameter.

        That's why I use a bit of JS to regenerate my cache when I'm done working. It looks like this (requires jquery):

        <script type="text/javascript">// <![CDATA[
        allcats = new Array();
        
        [[!getResources? parents=`52,1565,70,1564,80` &tpl=`allcats.tpl` &limit=`0`]];
        
        var m=0;
        for (x in allcats) {
        m++;
        }
        
        function milliDif()   
        {
           var d = new Date();
              return d.getTime()
        }
        
        function catfetch(m,i) {
        var t=setTimeout(function(){
        $('#url-list').append('<p>fetching '+allcats[i]+'...</p>');
        start = milliDif();
        $.get(allcats[i], function() {
        end = milliDif();
        elapsed = end - start;
        $('#url-list').append('<p>'+allcats[i]+' regenerated in '+elapsed+' ms</p>');
        i++;
        if (i<=m) catfetch(m,i);
        });
        },100);
        
        }
        
        catfetch(m,1);
        // ]]></script>
        <div id="url-list"></div>
        


        Where the parents are my main category pages, and allcats.tpl looks like this:

        n = [[+idx]];
        allcats[n] = '[[~[[+id]]]]';
        


        I have a page with nothing but this code on it, and I leave it unpublished. After I clear the cache, I just view the page and it regens all of my category pages.

        As for a better way to display images, the only thing I can think of is to make a plugin that uses phpThumbOf to create the thumb when you save a resource, and then store the name of the thumbnail file in a TV. Then just call the TV straight. I haven't implemented this though. Cached performance is fine, and improving uncached performance isn't the highest priority.
          • 3749
          • 24,544 Posts
          Nice idea.

          I'm playing with some PHP code that should refresh the whole cache. If it works, I'll release it as an extra.

          I think it will be a snippet first, but I'll probably make it either a component or a Site menu option once I figure out how to package it that way.
            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
            • 9102 ☆ A M B ☆
            • 318 Posts
            Yeah, Bob, that would be very cool. One caveat though -- you might want to include the option of some sort of brief delay between caching each resource. If you try to cache them all at once on a large site you'll bring the server to its knees.
              • 3749
              • 24,544 Posts
              Quote from: esnyder at Dec 10, 2011, 04:30 PM
              Yeah, Bob, that would be very cool. One caveat though -- you might want to include the option of some sort of brief delay between caching each resource. If you try to cache them all at once on a large site you'll bring the server to its knees.

              Good point, you could also run afoul of some bot-blocking scripts. I'll toss in a couple of properties for that.
                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