I’m looking at optimising a rather large site I’ve been adding to and adding to. The database has become pretty big (maybe 100,000 posts) and it has started slowing down somewhat and giving me “Mysql has gone away”errors. I’ve been reading about database optimisation and have ready some people saying you should only be looking to use 1-15 queries on a page.
Do people think the suggestion that only a handful of queries should be used on any page?
Am I correct in thinking that every time I use a WordPress function such as get_permalink() I am creating a new query and new connection the database?
I have some loops in there that literally loop through 100+ users at a time and use functions such as get_user_meta() in these loops – so would this mean I am literally making 100 database queries or are they somehow cached in WordPress?
Thanks
Looking a the source code of get_permalink(), that function not always generates additional queries. It depends on the particular situation. get_user_meta() is always performing aditional queries although they can be stored in wp cahe.
Take a look into Save queries for analysis and this helpful plugin. You will be able to see the total number of queries, time taking by each one and other useful information that will help you to know if using a especific function is generating aditional queries or not.
Use Redis for caching. Google is fetching my posts on 50-60 ms. before redis google was fetching on 700-800 ms.
http://www.jimwestergren.com/wordpress-with-redis-as-a-frontend-cache/