[wp-hackers] Stripping attachment handling from rewrite rules

aesqe aesqe at skyphe.org
Thu Feb 12 13:30:16 GMT 2009


Johan, thank you so much, because it would never cross my mind that 
something like attachment rewrite rules could be the cause of my problems.

A site I'm currently working on has nearly 300 pages, each with 5 to 20 
attachments, and it would take forever to load a single page.

Until I used your code,

<!-- <?php echo get_num_queries(); ?> queries. <?php timer_stop(1); ?> 
seconds. -->

was returning this:

<!-- 3906 queries. 34.944 seconds. -->

but now it returns this:

<!-- 91 queries. 1.687 seconds. -->

I'd say that's a big improvement :)




Thanks once again!


Bruno


On 7.2.2009 17:48, Johan Eenfeldt wrote:
> Inspired by the recent discussion of permalinks on wp-testers I took a
> closer look at my rewrite_rules.
>
> We use %postname% as permalink, which result in verbose rewrite_rules
> -- in our case ~8000 rules (~350KB).
>
> Looking a bit closer, most of that was various rewrites handling
> attachments -- all pictures on all pages got a few each. This is done
> to allow linking to and using them the same way as posts. Something we
> do not use.
>
> So I tried just strippin them:
>
> function filter_rewrite_attachment($content) {
> 	if (!is_array($content))
> 		return $content;
>
> 	foreach ($content as $key =>  $val) {
> 		if (strpos($val, 'attachment') !== false)
> 			unset($content[$key]);
> 	}
>
> 	return $content;
> }
> add_filter('page_rewrite_rules', 'filter_rewrite_attachment');
> add_filter('post_rewrite_rules', 'filter_rewrite_attachment');
>
> This got the size of rewrite_rules down to ~300 rules (~35KB), and
> seems to work just fine.
>
> We didn't really have any problems (yet?) by the proliferation of
> rewrite rules -- though changing it decreases the average mysql
> transfers by almost 50%!
>
> Anyone knows any reason not to do this?
>
> Thank you,
> Johan Eenfeldt
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
>
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 8.0.233 / Virus Database: 270.10.19/1938 - Release Date: 02/06/09 17:28:00
>

-- 
-._______________KAWAII!_______________.-
Skyphe.org : It'll all make sense one day
http://skyphe.org .:. http://breedart.org


More information about the wp-hackers mailing list