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: | 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.
- We are using a logging system that uses a custom post type, and had 10,000+ logs that had the same title.
- 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()
.
related: #39603