Optimize rewrite rule generation
|Reported by:||matthijs||Owned by:|
The problem was introduced after the upgrade from 2.6.5 to 2.7.
The site has a permalink structure of /%category%/%year%/%monthnum%/%day%/%postname%/
After the upgrade the blog runs more then 2400 queries per page load. The site works normal, only very very slow (of course).
Research into the queries being run shows wordpress is trying to insert the rewrite_rules in the wp_options table. Only problem is: the field rewrite_rules contains about 20,000 lines of code/rules, putting that single field in a text file is >1.2 Mb large. So it chokes on that.
Disabling plugins, re-importing the db file, renewing the wp files, nothing helps. Going back to 2.6.5 and then again upgrading reintroduces the problem.
Changing the permalink structure to something else, for example:
also solves the problem temporarily. As soon as I change back to
wordpress again tries to insert the huge query into the field rewrite_rules, which isn't possible.
Looking at the rewrite_rules it seems it repeats the same rules for every page and attachment, like
1- when I do an export of the posts to the xml file, install a fresh wp and then re-import the posts, the problem goes away. In that case, the field rewrite_rules, suddenly "only" contains around 5000 rewrite_rules.
2 - all the rules seem to relate to (older) versions of the pages and attachments
So maybe the problem is that wordpress is writing rules for every page revision and every page attachment it has ever had. The website is not that big, but with a few hundred pages, a few hundred attachments it seems to go into the 20,000 rules with this specific permalink structure. That could also explain that when I do the import of xml in a fresh install, there are no page revisions anymore and the rewrite rules are not that many.
I cannot imagine it is something else, because besides the fact that that one query is too large to be run, everything is fine. Database tables are in good condition, files are correct, I tried it on different servers, etc so I can almost certainly rule out another causes. Besides the fact that wp cannot run the query to insert the rewrite_rules, everything works fine, front- and backend.
Change History (42)
- Keywords needs-patch added; reporter-feedback removed
- Milestone set to 2.8
- Keywords dev-feedback added; permalinks rewrite_rules revisions removed
- Keywords needs-patch added; has-patch needs-testing dev-feedback removed
- Keywords has-patch needs-testing added; needs-patch removed
comment:23 in reply to: ↑ 22 Denis-de-Bernardy — 5 years ago
- Component changed from Permalinks to Optimization
- Keywords tested added; needs-testing removed
- Owner changed from ryan to Denis-de-Bernardy
- Status changed from new to accepted
- Owner Denis-de-Bernardy deleted
- Status changed from accepted to assigned
comment:27 scribu — 4 years ago
- Summary changed from Huge amount rewrite rules for page revisions after upgrade to Optimize rewrite rule generation
- Type changed from defect (bug) to enhancement
comment:30 scribu — 4 years ago
- Keywords health-check added; has-patch tested removed
- Milestone changed from Future Release to 3.0
comment:39 johnbillion — 3 years ago
- Keywords needs-patch health-check removed
- Resolution set to duplicate
- Status changed from assigned to closed