Make WordPress Core

Changeset 46178


Ignore:
Timestamp:
09/19/2019 02:05:25 AM (5 years ago)
Author:
boonebgorges
Message:

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.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment.php

    r46177 r46178  
    26662666    }
    26672667
    2668     // Do Trackbacks
    2669     $trackbacks = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE to_ping <> '' AND post_status = 'publish'" );
    2670     if ( is_array( $trackbacks ) ) {
    2671         foreach ( $trackbacks as $trackback ) {
    2672             do_trackbacks( $trackback );
    2673         }
    2674     }
    2675 
    2676     //Do Update Services/Generic Pings
     2668    // Do trackbacks.
     2669    $trackbacks = get_posts(
     2670        array(
     2671            'post_type'        => get_post_types(),
     2672            'suppress_filters' => false,
     2673            'nopaging'         => true,
     2674            'meta_key'         => '_trackbackme',
     2675            'fields'           => 'ids',
     2676        )
     2677    );
     2678
     2679    foreach ( $trackbacks as $trackback ) {
     2680        delete_post_meta( $trackback, '_trackbackme' );
     2681        do_trackbacks( $trackback );
     2682    }
     2683
     2684    // Do Update Services/Generic Pings.
    26772685    generic_ping();
    26782686}
  • trunk/src/wp-includes/post.php

    r46076 r46178  
    67876787    add_post_meta( $post_id, '_encloseme', '1' );
    67886788
     6789    $to_ping = get_to_ping( $post_id );
     6790    if ( ! empty( $to_ping ) ) {
     6791        add_post_meta( $post_id, '_trackbackme', '1' );
     6792    }
     6793
    67896794    if ( ! wp_next_scheduled( 'do_pings' ) ) {
    67906795        wp_schedule_single_event( time(), 'do_pings' );
Note: See TracChangeset for help on using the changeset viewer.