• Since a few weeks a wordpress site of mine has gotten very slow. On inspection I found out it runs about 2400 database queries for each page. What I did so far to try to find the problem:

    – Use default theme
    – Disable all plugins
    – Install on a different (local) webhost
    – Replace all wordpress files with fresh ones
    – Remove the code in the template which does the loop
    – Remove any function in the templates which might run a query

    So far without any result, the footer still reports > 2000 queries.

    I also installed the plugin debug queries, which reports an enormous amount of queries. Looking in phpmyadmin I can’t see anything unusual in the database tables at first sight. A few thousand posts, 13 Mb for all tables combines.

Viewing 4 replies - 16 through 19 (of 19 total)
  • Thread Starter matthijs

    (@matthijs)

    Ok I’ve taken a closer look at the rewrite rules and it’s absolutely unclear why there are so many rules. If I just look at one Page, there are maybe a thousand rewrite rules for that single page, something like:

    s:53:\"vacancies/phd-studentship-wales/attachment/([^/]+)/?$\";
    s:32:\"index.php?attachment=$matches[1]\";
    s:63:\"vacancies/phd-studentship-wales/attachment/([^/]+)/trackback/?$\";
    s:37:\"index.php?attachment=$matches[1]&tb=1\";
    s:83:\"vacancies/phd-studentship-wales/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$\";
    s:49:\"index.php?attachment=$matches[1]&feed=$matches[2]\";
    s:78:\"vacancies/phd-studentship-wales/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$\";
    s:49:\"index.php?attachment=$matches[1]&feed=$matches[2]\";
    s:78:\"vacancies/phd-studentship-wales/attachment/([^/]+)/comment-page-([0-9]{1,})/?$\";
    s:50:\"index.php?attachment=$matches[1]&cpage=$matches[2]\";
    s:46:\"(vacancies/phd-studentship-wales)/trackback/?$\";
    s:37:\"index.php?attachment=$matches[1]&tb=1\";
    s:66:\"(vacancies/phd-studentship-wales)/feed/(feed|rdf|rss|rss2|atom)/?$\";
    s:49:\"index.php?attachment=$matches[1]&feed=$matches[2]\";
    s:61:\"(vacancies/phd-studentship-wales)/(feed|rdf|rss|rss2|atom)/?$\";
    s:49:\"index.php?attachment=$matches[1]&feed=$matches[2]\";
    s:54:\"(vacancies/phd-studentship-wales)/page/?([0-9]{1,})/?$\";
    s:50:\"index.php?attachment=$matches[1]&paged=$matches[2]\";
    s:61:\"(vacancies/phd-studentship-wales)/comment-page-([0-9]{1,})/?$\";
    s:50:\"index.php?attachment=$matches[1]&cpage=$matches[2]\";
    s:46:\"(vacancies/phd-studentship-wales)(/[0-9]+)?/?$\";
    s:49:\"index.php?attachment=$matches[1]&page=$matches[2]\";
    s:35:\"vacancies/473/attachment/([^/]+)/?$\";
    s:32:\"index.php?attachment=$matches[1]\";
    s:45:\"vacancies/473/attachment/([^/]+)/trackback/?$\";
    s:37:\"index.php?attachment=$matches[1]&tb=1\";
    s:65:\"vacancies/473/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$\";
    s:49:\"index.php?attachment=$matches[1]&feed=$matches[2]\";
    s:60:\"vacancies/473/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$\";
    s:49:\"index.php?attachment=$matches[1]&feed=$matches[2]\";
    s:60:\"vacancies/473/attachment/([^/]+)/comment-page-([0-9]{1,})/?$\";
    s:50:\"index.php?attachment=$matches[1]&cpage=$matches[2]\";
    s:28:\"(vacancies/473)/trackback/?$\";

    That specific page has currently around 100 words and maybe 2 attachments. Somehow it seems it “remembers” all page revisions or prior versions of that page?

    I’m also looking into the possibility that those pages which have the many rules, have had different attachments to them in their prior version. Looking at the rewrite rules, many have to do with attachments. The above page, “vacancies” currently has 26 attachments if you look in the add image > gallery. Only 2 of them are currently linked from the page.

    But in that case it seems like to be a bug in wordpress. Why is it creating those endless rules?

    Thread Starter matthijs

    (@matthijs)

    Another thing I discovered. The bug has appeared from the moment I upgraded the website to 2.7.

    I have backups of the database from all prior versions. If I import the 2.6.5 db file and run 2.6.5 it is fast (14-20 queries). As soon as I upgrade to 2.7 the problem starts. The upgrade process seems to run fine, just as always. I can go back and forth (all local) and repeat the process and see how the problem appears in 2.7

    Thread Starter matthijs

    (@matthijs)

    Update: the problem is caused by the combination of attachments of pages (and posts) and the permalink structure
    /%category%/%year%/%monthnum%/%day%/%postname%/

    Because of the nature of that permalink structure, wordpress writes about 10-20 rewrite_rules for each attachment and page. So with a site with a few hundred pages and a few hundred attachments, the amount of rewrite_rules soon explodes to many thousands. About 20,000 in my case. That doesn’t scale.

    See this ticket:
    http://trac.wordpress.org/ticket/8958
    See this older ticket as well:
    http://trac.wordpress.org/ticket/3614
    and this forum thread:
    http://wordpress.org/support/topic/99953?replies=31

    The older ticket has a patch attached, but I’m not sure if an wp 2.0 patch is going to work on a 2.7 version. I’d rather see a real solution then a workaround patch (which might cause other problems).

    So I’m having the same problem. Basically, I can’t use permalinks without turning my database to mud. Another weird thing is I can’t find a ‘rewrite_rules’ entry in my wp-options table. Is there any way to simply reboot the rewrite rules? How do i just start over with this? The data I’m using was also imported using the WP Export/Import tools, so you’d think it’d be cleared up. Any ideas what I can do to get this working? I have been using /%postname%/ for my permalinks, but changing that to /blog/%postname% didn’t work either.

    Help is greatly appreciated.

Viewing 4 replies - 16 through 19 (of 19 total)
  • The topic ‘WordPress running thousands of queries’ is closed to new replies.