Make WordPress Core

Opened 15 years ago

Closed 14 years ago

#5717 closed defect (bug) (invalid)

404 handling optimization

Reported by: misterbisson's profile misterbisson Owned by: ryan's profile ryan
Milestone: Priority: normal
Severity: normal Version: 2.3.2
Component: Optimization Keywords: needs-patch needs-testing
Focuses: Cc:


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: .

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 (1)

404fix.diff (469 bytes) - added by misterbisson 15 years ago.

Download all attachments as: .zip

Change History (16)

15 years ago

#1 follow-up: @misterbisson
15 years ago

Please ignore or delete the first attached file, 404fix.diff.txt
I'm an idiot.

#2 in reply to: ↑ 1 @lloydbudd
15 years ago

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.

#3 @Bobcat
15 years ago

Will this help with ticket #5490 ?

#4 @ryan
15 years ago

  • Owner changed from anonymous to ryan

#5 @ryan
15 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [6940]) Skip main posts query if 404. Props misterbisson. fixes #5717

#6 @darkdragon
15 years ago

  • Milestone changed from 2.6 to 2.5

#7 @rubys
15 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

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:

#8 @rubys
15 years ago

  • Cc rubys added

#9 @ryan
15 years ago

(In [6956]) Revert [6940]. Breaks atompub. see #5717

#10 @ryan
15 years ago

Reverted for now. I'll probably push this to 2.6 since it seems ripe for unintended consequences.

#11 @ryan
15 years ago

  • Milestone changed from 2.5 to 2.6

#12 @DD32
14 years ago

  • Keywords has-patch needs-testing added


#13 @Denis-de-Bernardy
14 years ago

  • 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?

#14 @Denis-de-Bernardy
14 years ago

alternatively, maybe toss " and 0 = 1 " in the query to make sure the optimizer immediately returns zero rows?

#15 @Denis-de-Bernardy
14 years ago

  • Milestone 2.9 deleted
  • Resolution set to invalid
  • Status changed from reopened to closed

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.

Note: See TracTickets for help on using tickets.