Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#45855 closed defect (bug) (duplicate)

Impossible to short circuit looping query in wp_unique_post_slug()

Reported by: ryankanner's profile ryan.kanner Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: has-patch
Focuses: performance Cc:

Description

We've recently been seeing some massive slowdowns on a few of our (fairly large) sites. The culprit seems to be coming from the queries within the wp_unique_post_slug() function.

We tracked down the exact cause to two different scenarios that are causing many posts with duplicate title's to generate a ton of queries to find an open suffix to append to the slug.

  1. We are using a logging system that uses a custom post type, and had 10,000+ logs that had the same title.
  2. One site has been publishing a post titled "Today in history" every day for the past 8 years.

The problem is that there is currently no way to short circuit the queries looking for an open suffix here. There are a few filters like wp_unique_post_slug_is_bad_flat_slug in the function, but they are checked in addition to other things, in this filter's instance it checks to see if the slug already exists within the same if statement and continues on with the do while loop if it already exists.

I'm proposing adding a wp_unique_post_slug_pre filter at the beginning of this function to change the desired post name before continuing. I feel like this would be the least intrusive way to add this functionality. This would bring parity to the wp_unique_term_slug() function that can perform this type of action. The filter to do this was added in #20783 (funny enough that issue was to create parity with wp_unique_post_slug().

Attachments (1)

45855.diff (1.1 KB) - added by ryan.kanner 6 years ago.

Download all attachments as: .zip

Change History (4)

@ryan.kanner
6 years ago

#2 @ryan.kanner
6 years ago

  • Keywords has-patch added

#3 @ocean90
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed
  • Version trunk deleted

Duplicate of #21112.

Note: See TracTickets for help on using tickets.