Tip: speed up your site if you are using a lot of options

This might speed you up, or not, you have to be in the same boat as me to benefit.



We use a LOT of options with pics and such. What happened, these categories that held the products with a lot of options became drastically slow once we added all the options.



I knew right away because we did add options automatically in bulk (I have a script in another post). So, I could judge that the categories with these products suddenly took 5+ seconds to open up. The parent category took about 7-10 seconds just to produce html.



Something had to be done. I went to fn.database.php and hooked up my own line that would write each DB access with debug trace, so I would know fom where the request comes.



In one page load it generated like 200Megs of text. I was like wow. Anyway, I found that even if you use Category_view_without_options the cs-cart still dips into every freaking single option and gets its data for its array to pass to smarty. Smarty then would either use info about options or not, depending on what TPL was handling the assigned array.



Therefore, I had like 17,000 db requests about options, like its thumbnail…



example of 17,000 lines of this:



```php SELECT pair_id, image_id, detailed_id FROM cscart_images_links WHERE object_id = 10170 AND object_type = ‘variant_image’ AND type = ‘V’

SELECT image_path, alt, image_x, image_y FROM cscart_images WHERE image_id = 5519

SELECT pair_id, image_id, detailed_id FROM cscart_images_links WHERE object_id = 10156 AND object_type = ‘variant_image’ AND type = ‘V’

SELECT image_path, alt, image_x, image_y FROM cscart_images WHERE image_id = 5506

SELECT pair_id, image_id, detailed_id FROM cscart_images_links WHERE object_id = 10157 AND object_type = ‘variant_image’ AND type = ‘V’

SELECT image_path, alt, image_x, image_y FROM cscart_images WHERE image_id = 5507

SELECT pair_id, image_id, detailed_id FROM cscart_images_links WHERE object_id = 10158 AND object_type = ‘variant_image’ AND type = ‘V’

SELECT image_path, alt, image_x, image_y FROM cscart_images WHERE image_id = 5508

SELECT pair_id, image_id, detailed_id FROM cscart_images_links WHERE object_id = 10159 AND object_type = ‘variant_image’ AND type = ‘V’

SELECT image_path, alt, image_x, image_y FROM cscart_images WHERE image_id = 5509

SELECT pair_id, image_id, detailed_id FROM cscart_images_links WHERE object_id = 10160 AND object_type = ‘variant_image’ AND type = ‘V’

SELECT image_path, alt, image_x, image_y FROM cscart_images WHERE image_id = 5510

SELECT pair_id, image_id, detailed_id FROM cscart_images_links WHERE object_id = 10161 AND object_type = ‘variant_image’ AND type = ‘V’

SELECT image_path, alt, image_x, image_y FROM cscart_images WHERE image_id = 5511 ```



My problem was that the category itself has no use for freaking options but it was reading it off and passing to smarty as a default behavior.



I decided that a good place to stop this was fn.cataglog.php



I added on the very top of function fn_get_product_options



```php

//ignore stupid DB lookups on categories

$thenum=explode(‘=’,$_SERVER[‘REQUEST_URI’]);

if(is_array($thenum)){

if(count($thenum)==3){

if($thenum[1]==‘categories.view&category_id’){

$the_n=(int)$thenum[2];

if($the_n>0){

$arr=array(202,205,165,167,172,192,196,203,166,173,183,193,197,204,184,179,169,174,177,194,198,175,170,178,191,199,185,180,195,200,186,188,189,206);

if(in_array($the_n,$arr)) return array();

}

}

}

}

```



The array is the ids of my categories, I know, it is not very dynamic to hard code them, but for us it is more important to launch the site soon.



The category ids you can find in db or in the links in admin->catalog



What this script does, it checks if the current URL is a category with the given id, then passes an empty array for options, this really boosts the performance on our end. For everything else it does its default behavior where it gets the options.



PS: If you are using a lot of pics in your options, you might read this: [url]http://forum.cs-cart.com/vbugs.php?do=view&vbug_id=1942[/url]



------------------------------------------------------------------------------------------------------------------------

EDIT: Even the front page is getting the options. It might be a little more responsive if to exclude it too.

I think I may give this a try, does anyone know where fn.catalog.php is now?



2.1.2



Thanks

John

[quote name=‘johnbol1’]I think I may give this a try, does anyone know where fn.catalog.php is now?



2.1.2



Thanks

John[/QUOTE]



/core/

Works a treat





John