Make WordPress Core

Opened 7 years ago

Closed 4 years ago

Last modified 4 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:


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 7 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 @Viper007Bond7 years ago

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

comment:2 @ryan7 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.

@ryan7 years ago

comment:3 @Denis-de-Bernardy6 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-Bernardy6 years ago

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

comment:5 @Denis-de-Bernardy6 years ago

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

comment:6 follow-up: @scribu6 years ago

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

comment:7 in reply to: ↑ 6 @Viper007Bond6 years ago

Replying to scribu:

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

It's the thing in the URL.


comment:8 @ryan6 years ago

  • Milestone changed from 2.9 to Future Release

comment:9 @johnbillion4 years ago

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

This is being addressed in #16687

comment:10 @johnbillion4 years ago

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

comment:11 @SergeyBiryukov4 years ago

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