[wp-hackers] get_userdata and _fill_user causing huge number of database queries

Michael Pretty mpretty at voceconnect.com
Thu Mar 4 15:24:05 UTC 2010


A couple of suggestions:

1.  Add paging to your listing so that you don't loop through 50+ posts 
on a single page.
2.  In WP 3.0 there has been a revamp of the user handling with 
caching.   At the beginning of this page, before you start your loop and 
calling the_post(), you can loop through $_GLOBAL['wp_query']->posts and 
get the user_ids that are needed to be cached.  Then you can use the new 
functionality for cache_users() to go ahead and cache the user data with 
a single query.

-prettyboymp

On 3/4/10 9:19 AM, Simon B wrote:
>> The test script is really the worst case scenario, I was under the
>> impression you were seeing those 101 queries on the home page/blog page.
>>
>> Whilst i havnt looked into trunk's user caching changed of late yet, It
>> makes sense to mass-load/cache the user data in one swipe on get_posts where
>> multiple authors are concerned.
>>
>>
>>      
> It's not a worst case for me, it's actual case! And it's likely to be the
> most-visited page on the site...
>
> I realise this is not your average use of WordPress, but if the user data
> could be cached in one swipe that would be a big help.
>
> Luckily the site is unlikely to see very high traffic so I'm confident our
> server can cope fine, but obviously saving 100 db queries would be nice!
>
> Thanks for your time,
> Simon
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>    



More information about the wp-hackers mailing list