update_post_caches causes time-out on large queries if cache_results flag not set
|Reported by:||bytesmasher||Owned by:|
I ran into this problem when debugging why the Advanced Custom Fields plugin's option screen was timing out on my site. I have over 8000 items in my wp_posts table, and the plugin pulls back every post to populate a dropdown (I plan on bringing up this issue with the plugin author)
I was relieved to find out that it wasn't actually the query that was choking, (for a moment I thought mysql was horribly misconfigured) but actually the update_post_caches function.
I realize that the cache_results flag was added to avoid this issue, but it occurs to me that many plugin developers will not foresee sites with as much content as mine.
My suggestion is this: Place a "cache_threshold" option in the Wordpress settings... make the default something reasonable like 20 (or maybe even ignore this option all together and grab the value from the posts_per_page option, as set on the admin screen.. it's important it come from the admin screen and not the query options because in the case I encountered it, the posts per page option in the query was set to -1). If the cache_results flag is not set, check after the initial database query is completed to grab the number of returned posts... if it's more than the cache_threshold, then don't call update_post_caches.
This will increase the stability of the core, and prevent plugins from accidentally breaking things with unreasonable queries on large sites.
Sorry if anything in this ticket doesn't make sense... it's early and I haven't had my coffee yet.