Slow database queries on archive
-
We are running a high traffic WordPress site with more than 65,000 posts.
We are noticing the two following slow database queries whenever an archive page is loaded and they are causing a lot of server load.
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (11) ) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10
and
SELECT wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (11) ) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10
We are using a standard loop to call the latest 10 posts on archive.php:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <article class="infinite-article-wide"> <div class="archive-image" ><a href="<?php the_permalink() ?>" rel="bookmark" ><div class="subhead-mini" ><? echo get_post_meta($post->ID, 'article-signpost', true) ?></div><img src="<? echo get_post_meta($post->ID, 'leadimage', true) ?>" alt="<?php the_title(); ?>" /></a></div> <div class="archive-data"> <a href="<?php the_permalink() ?>" rel="bookmark" > <h2 class="archive-h2"><?php the_title(); ?></h2> </a> <h3 class="archive-h3"><? echo get_post_meta($post->ID, 'standfirst', true) ?></h3> </div> <div style="clear:both"></div> </article> <?php endwhile; else: ?> <?php endif; ?>
Is there a simple way to optimise these queries? Our archive pages just need to be set up to show the 10 latest posts from that category / tag and a link to the next page of posts.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Slow database queries on archive’ is closed to new replies.