Ticket #5717 (closed defect (bug): invalid)

Opened 4 years ago

Last modified 3 years ago

404 handling optimization

Reported by: misterbisson Owned by: ryan
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

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

Change History

comment:1 follow-up: ↓ 2   misterbisson4 years ago

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

comment:2 in reply to: ↑ 1   lloydbudd4 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.

Will this help with ticket #5490 ?

comment:4   ryan4 years ago

  • Owner changed from anonymous to ryan

comment:5   ryan4 years ago

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

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

  • Milestone changed from 2.6 to 2.5
  • 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

  • Cc rubys added

comment:9   ryan4 years ago

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

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

  • Milestone changed from 2.5 to 2.6
  • 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.

Note: See TracTickets for help on using tickets.