WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 3 years ago

Last modified 3 years ago

#7443 closed enhancement (duplicate)

Having many Pages with the same stub causes excess queries

Reported by: Viper007Bond Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.6
Component: Optimization Keywords: needs-patch
Focuses: Cc:

Description

If you have many Pages with the same stub, many queries can be required to view the Page. This is because it first grabs all Pages with the stub (1 query). Then it loops through each result and queries the details for that result's parent looking for a match.

Instead, why not turn the IDs to search for into a list and grab all of those parents at once? It's a little heavier query, but it's one query rather than tons. Then you can loop through those results checking via PHP.

Thoughts? Am I missing something?

Attachments (1)

7443.diff (1.2 KB) - added by ryan 6 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 Viper007Bond6 years ago

Otto pointed out on wp-hackers that get_post_ancestors() may do the trick.

comment:2 ryan6 years ago

We need to walk the parents, not the ancestors.

This untested patch might help a bit. It does one query for the immediate parents, which primes the cache.

ryan6 years ago

comment:3 Denis-de-Bernardy5 years ago

another alternative would be to walk nothing: when implementing permalink history (another ticket), I'll need to insert post_meta fields. we could then do a direct db check to find a post against a post_meta value.

comment:4 Denis-de-Bernardy5 years ago

  • Owner changed from anonymous to Denis-de-Bernardy
  • Status changed from new to accepted

comment:5 Denis-de-Bernardy5 years ago

  • Owner Denis-de-Bernardy deleted
  • Status changed from accepted to assigned

comment:6 follow-up: scribu5 years ago

Sorry for the noob question, but what exactly is a page stub?

comment:7 in reply to: ↑ 6 Viper007Bond5 years ago

Replying to scribu:

Sorry for the noob question, but what exactly is a page stub?

It's the thing in the URL.

http://site.com/post-parent/this-is-the-slug/

comment:8 ryan4 years ago

  • Milestone changed from 2.9 to Future Release

comment:9 johnbillion3 years ago

  • Resolution set to duplicate
  • Status changed from assigned to closed

This is being addressed in #16687

comment:10 johnbillion3 years ago

At least, I think it is. Re-open if not.

comment:11 SergeyBiryukov3 years ago

  • Milestone Future Release deleted
Note: See TracTickets for help on using tickets.