Huge amount of queries on my site

My site is reaching CPU limits all the time, I just ran Debug Queries and got more than 4000 queries, no wonder site is slow.

Related posts

Leave a Reply

3 comments

  1. Standard permalink advice is to not start with postnames, tags, categories or authors:

    From the Codex on Permalinks

    For performance reasons, it is not a good idea to start your permalink structure with the category, tag, author, or postname fields. The reason is that these are text fields, and using them at the beginning of your permalink structure it takes more time for WordPress to distinguish your Post URLs from Page URLs (which always use the text “page slug” as the URL), and to compensate, WordPress stores a lot of extra information in its database (so much that sites with lots of Pages have experienced difficulties). So, it is best to have at least two path segments in your post’s permalink structure such as /%year%/%postname%/ or even /posts/%postname%/. (Some people recommend /%post_id%/%postname%/ which works for performance reasons but others recommend against it because it is unfriendly to users in the many contexts in which users interact with URLs.) See Otto’s technical writeup on the topic as well as this wp-testers discussion.

  2. How many pages do you have? Pages.. not posts.

    I’d have the same problem in the past with a site with a LOT of pages.

    It’s even documented as a bug.

    If it is your case, try setting $use_verbose_page_rules to false in the WP_rewrite class

    Edit:
    Class WP_Rewrite
    bool $use_verbose_page_rules = true
    Whether to write every mod_rewrite rule for WordPress pages.

    since: 2.5.0
    access: public

    To change it, try (not tested):

    add_action( 'rewrite_rules_array','changeVerboseRules' );
    
    function changeVerboseRules(){
        global $wp_rewrite;
        $wp_rewrite->use_verbose_page_rules = false;
    }
    

    Anyway, this is a hack. You should read this.