wp_admin edit.php slow with lots of queries

I have about 4,000 posts. Currently when I click on All Posts (edit.php) it’s taking about 10 seconds to load and I’m showing approximately 1000 queries!

Most of them look like…

SELECT t.*, tt.* FROM wp_terms AS t 
INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id 
INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id 
WHERE tt.taxonomy IN ('post_tag') AND tr.object_id IN (37336) 
ORDER BY t.name ASC

If I deactivate WordPress SEO, I can cut the number of queries in half but the page still takes approximately 7 seconds to load.

Just for fun, I deactivated all my plugins to no significant performance improvement. I’ve tweaked MySQL and PHP in about every way I can think of. The issue is the exorbitant amount of queries.

Any way to tweak WordPress here to use less? I have tried deleting revisions, etc. Nada. Really could use some insight here.

Thanks!

2 Answers
2

One way to do this (and yes, it is ugly and hackish) is to create a custom page having a custom page template that draws out all of your posts and creates the proper admin url links for each one.

For example:

<?php
/*
Template Name: View Posts Quickly
*/
if ( !is_user_logged_in() ) {
   # Redirect the user or use wp_die('Permission denied') or throw a 404
} else if ( !current_user_can('activate_plugins') ) {
   # Permission denied
} else {
   $query_args = array(
      'post_type' => 'post',
      'posts_per_page' => '-1',
      'post_status' => array( 'any' ),
      'orderby' => 'title',
      'order' => 'asc'
   );
   $post_list = new WP_Query( $query_args );
   if ( ! $post_list->have_posts() ) {
      # Tell user no posts found
   } else {
      echo '<h2>The Post List:</h2><ul>';
      while ( $post_list->have_posts() ) {
         $current = $post_list->next_post();

         # Modify the below to include any extra data wanted for each item
         echo get_post_edit_link( $current->post_title, '<li>', '</li>', $current->ID);
      }
      echo '</ul>';
   }
}
?>

Obviously the above could be turned into an actual admin page if wanted. I do it on my own sites when I want to have a very different view of things on the back end.

Using the above (and, of course, creating a private page and setting the template to use the above template) will get one a cleaner, faster list.

But the normal display of wordpress posts displays a lot of extra data using a lot of extra queries due to the database design. The db design gives good flexibility, but one trade off is the ability to draw lots of related information in just one or two queries.

A better way might be to kill those extra queries by stripping out the term columns displayed in the post list (but you would lose the various sorting, limiting, etc. tools that the wordpress list gives, though you could build your own filters, sorting, etc. in as wanted) using the manage_*_posts_columns filter.

Leave a Comment