Optimize verbose attachment rules
|Reported by:||duck_||Owned by:|
|Component:||Rewrite Rules||Keywords:||needs-patch dev-feedback needs-unit-tests|
Looking at the rules created for verbose pages it seems that there are a large number of redundant rules created specifically for attachments.
page-slug/attachment-slug/attachment/([^/]+)/?$ => index.php?attachment=$matches another-page/another-attachment/attachment/([^/]+)/?$ => index.php?attachment=$matches page-slug/attachment/([^/]+)/?$ => index.php?attachment=$matches another-page/attachment/([^/]+)/?$ => index.php?attachment=$matches ...
As well as the associated trackback, feed and comment page rules for each.
I think we could get rid of specific attachment rewrite rules for pages and their attachments and replace them with a catch-all rewrite for page attachments:
.+?/attachment/([^/]+)/?$ => index.php?attachment=$matches
I also set the flag to include paged requests (slug/page/xx/) to false for pages and page attachments for verbose rules. I think think this could also be applied to post rewrite rules and non-verbose page rules since neither are paged, though they have pages (slug/xx/), but I will open another ticket for that. This is the part I am less sure about since myself and others have been confused by the paged rules before (page/xx/), so correct me if I'm wrong here (or anywhere else!).
For the /%postname%/ structure the attached patch cuts the number of rewrites rules for 1297 pages from 14361 to 6562. This translated to a drop from 0.42s to 0.31s average response time in testing (tested using siege with one concurrent user for 30 seconds) on a single post permalink so near the bottom of the rewrite stack for verbose page rules in trunk.
I have run this patch against the current tests for WP_Query and WP_Rewrite (test_query.php in the unit-tests SVN) using several different verbose rewrite structures, including /%postname%/ and /%category%/%postname%/. The only 'fail' was for the test of paged rewrites for pages which I mentioned above (there were a couple of other tests that showed up as fails initially but further investigation proved to be problems with conflicting page and post slugs). This gives me confidence in the patch but even more rigorous testing is definitely required.
I also wrote a patch which utilised a new parameter for generate_rewrite_rules() to disable adding the attachment rules, but this didn't seem so clean.
Related: #16687 which is for %postname% in particular rather than all verbose structures
Change History (13)
- Milestone 3.3 deleted
- Resolution set to duplicate
- Status changed from new to closed
5 years ago
- Keywords dev-feedback added
- Resolution duplicate deleted
- Status changed from closed to reopened
- Summary changed from Optimize verbose page rules to Optimize verbose attachment rules