Slow Loading Help Please

Permalink
I have this crazy page type with a big hard coded mess that I need to speed up. It creates several pagelists with a random image for each pagelist group but it takes forever to load. If anyone can give me some help to speed it up it would be much appreciated. You can see the page here:
http://www.tcalw.og/sports
and the code:
<?php
                $mcc = new Area('Main');
                $mcc->display($c);
               Loader::model('attribute/type');
               Loader::model('attribute/categories/collection');
               $ak = CollectionAttributeKey::getByHandle('sport_group');
               $satc = new SelectAttributeTypeController(AttributeType::getByHandle('select'));
               $satc->setAttributeKey($ak);
               $values = $satc->getOptions();
               foreach ($values as $v) {
                  Loader::model('page_list');
                  Loader::model('file_list');
                  Loader::model('file_set');
                  $im = Loader::helper('image');   
                  $fs = FileSet::getByName($v->value);


Thanks!

 
jordanlev replied on at Permalink Reply
jordanlev
I have a few ideas, but you're going to need to do some trial and error testing to see what really works.

First of all, the easy stuff: move all of the Loader::model() and Loader::helper() calls to the top, above the loop. There's no need to keep re-calling that on every loop iteration. But I doubt this is causing a major slowdown.

Next up I'd look at the thumbnail generation. It's possible that because it's showing different random images each time, you're not really re-using the same images and hence the code never has a chance to re-use cached thumbnails (because it's always showing different images). The question here is: how many different images are there to choose from?

The last thing I can think of is to try to reduce the database calls. So instead of getting every sport group and then for each sport group getting each page, you might want to retrieve *all* pages and then use php code to separate them out by sport group. I'm not sure if or how the C5 API's will let you do this, so you may ultimately need to resort to writing your own SQL query that JOINs the pages with the attribute. Attributes are great and a necessary way of doing things in a flexible system like Concrete5, but unfortunately there's the downside that you can't easily query them with their associated records and hence you get performance issues in edge cases like this.

So hopefully the problem is with the thumbnail images :)