WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/19/2019 02:05:25 AM (3 months 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.

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.