Ticket #5717 (closed defect (bug): invalid)
404 handling optimization
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Optimization | Version: | 2.3.2 |
| Severity: | normal | Keywords: | needs-patch needs-testing |
| Cc: | rubys |
Description
With permalinks enabled, requests for non-existing URL paths result in a resource intensive select. The problem is that WP::query_posts() doesn't halt execution when WP::parse_request() 404s, causing WP_Query::get_posts() to fetch the x most recent posts. More details: http://maisonbisson.com/blog/post/12035 .
The attached patch simply short-circuits WP::query_posts() if there's a 404. At rboren's suggestion, it also calls WP_Query::parse_query(), as some templates expect it to have run.
Honestly not sure if did_permalink is necessary, but the code works in my environments.
Attachments
Change History
comment:1
follow-up:
↓ 2
misterbisson — 4 years ago
Please ignore or delete the first attached file, 404fix.diff.txt I'm an idiot.
Replying to misterbisson:
Please ignore or delete the first attached file, 404fix.diff.txt I'm an idiot.
Deleted. I assure you, you are not an idiot! I have met many people acting idiotic.
- Status changed from new to closed
- Resolution set to fixed
- Status changed from closed to reopened
- Resolution fixed deleted
I haven't invested why just yet, but this change totally and completely breaks AtomPub. I wouldn't be surprised if it broke XML-RPC too. Details:
http://intertwingly.net/projects/wordpress-atompub/report.html http://intertwingly.net/projects/wordpress-atompub/apptestsuite.out
comment:10
ryan — 4 years ago
Reverted for now. I'll probably push this to 2.6 since it seems ripe for unintended consequences.
comment:12
DD32 — 3 years ago
- Keywords 404 optimization has-patch needs-testing added; 404, optimization, removed
Revisit?
- Keywords needs-patch added; 404 optimization query_posts has-patch removed
would it be valid to merely dump the $this->posts = $wpdb->get_results($this->request); call when it's a 404?
alternatively, maybe toss " and 0 = 1 " in the query to make sure the optimizer immediately returns zero rows?
- Status changed from reopened to closed
- Resolution set to invalid
- Milestone 2.9 deleted
I cannot get the error field to fill up when doing the query call a single time.
Please re-open with step by step instructions to reproduce if it is still relevant in trunk.

