Improve performance of trackback query in `do_all_pings()`.
Previously, the direct SQL query used to identify trackbacks in `do_all_pings()` performed poorly, due to an unindexed query against the `to_ping` column. We improve performance in two ways. First, we switch to using a postmeta flag for posts that require trackbacks to be sent; queries joining against the postmeta table that check only the `meta_key` are generally quite fast. Second, we switch to the use of `WP_Query`, making the query cacheable and filterable using standard methods. Props dshanske, spacedmonkey, janw.oostendorp, mrmadhat, birgire. Fixes #36824. Built from https://develop.svn.wordpress.org/trunk@46178 git-svn-id: http://core.svn.wordpress.org/trunk@45990 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
aa7d063af2
commit
da8a602ad6
|
@ -2665,15 +2665,23 @@ function do_all_pings() {
|
|||
do_enclose( null, $enclosure->ID );
|
||||
}
|
||||
|
||||
// Do Trackbacks
|
||||
$trackbacks = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE to_ping <> '' AND post_status = 'publish'" );
|
||||
if ( is_array( $trackbacks ) ) {
|
||||
foreach ( $trackbacks as $trackback ) {
|
||||
do_trackbacks( $trackback );
|
||||
}
|
||||
// Do trackbacks.
|
||||
$trackbacks = get_posts(
|
||||
array(
|
||||
'post_type' => get_post_types(),
|
||||
'suppress_filters' => false,
|
||||
'nopaging' => true,
|
||||
'meta_key' => '_trackbackme',
|
||||
'fields' => 'ids',
|
||||
)
|
||||
);
|
||||
|
||||
foreach ( $trackbacks as $trackback ) {
|
||||
delete_post_meta( $trackback, '_trackbackme' );
|
||||
do_trackbacks( $trackback );
|
||||
}
|
||||
|
||||
//Do Update Services/Generic Pings
|
||||
// Do Update Services/Generic Pings.
|
||||
generic_ping();
|
||||
}
|
||||
|
||||
|
|
|
@ -6786,6 +6786,11 @@ function _publish_post_hook( $post_id ) {
|
|||
}
|
||||
add_post_meta( $post_id, '_encloseme', '1' );
|
||||
|
||||
$to_ping = get_to_ping( $post_id );
|
||||
if ( ! empty( $to_ping ) ) {
|
||||
add_post_meta( $post_id, '_trackbackme', '1' );
|
||||
}
|
||||
|
||||
if ( ! wp_next_scheduled( 'do_pings' ) ) {
|
||||
wp_schedule_single_event( time(), 'do_pings' );
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.3-alpha-46177';
|
||||
$wp_version = '5.3-alpha-46178';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue