[wp-trac] [WordPress Trac] #45855: Impossible to short circuit looping query in wp_unique_post_slug()
WordPress Trac
noreply at wordpress.org
Mon Jan 7 21:51:20 UTC 2019
#45855: Impossible to short circuit looping query in wp_unique_post_slug()
-------------------------------+-----------------------------
Reporter: ryan.kanner | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Posts, Post Types | Version: trunk
Severity: normal | Keywords:
Focuses: performance |
-------------------------------+-----------------------------
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()`.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/45855>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list