Make WordPress Core


Ignore:
Timestamp:
08/13/2025 04:26:33 PM (8 months ago)
Author:
SergeyBiryukov
Message:

Export: Split the query for post authors in wxr_authors_list() into smaller chunks.

This aims to avoid a fatal error when attempting to export content on larger WP instances with a lot of data.

Follow-up to [15961], [28731].

Props bor0, SirLouen, SergeyBiryukov.
Fixes #63503.

File:
1 edited

Legend:

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

    r60630 r60632  
    406406
    407407        if ( ! empty( $post_ids ) ) {
    408             $post_ids = array_map( 'absint', $post_ids );
    409             $and      = 'AND ID IN ( ' . implode( ', ', $post_ids ) . ')';
     408            $post_ids       = array_map( 'absint', $post_ids );
     409            $post_id_chunks = array_chunk( $post_ids, 20 );
    410410        } else {
    411             $and = '';
     411            $post_id_chunks = array( array() );
    412412        }
    413413
    414414        $authors = array();
    415         $results = $wpdb->get_results( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status != 'auto-draft' $and" );
    416         foreach ( (array) $results as $result ) {
    417             $authors[] = get_userdata( $result->post_author );
     415
     416        foreach ( $post_id_chunks as $next_posts ) {
     417            $and = ! empty( $next_posts ) ? 'AND ID IN (' . implode( ', ', $next_posts ) . ')' : '';
     418
     419            $results = $wpdb->get_results( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status != 'auto-draft' $and" );
     420
     421            foreach ( (array) $results as $result ) {
     422                $authors[] = get_userdata( $result->post_author );
     423            }
    418424        }
    419425
    420426        $authors = array_filter( $authors );
     427        $authors = array_unique( $authors, SORT_REGULAR ); // Remove duplicate authors.
    421428
    422429        foreach ( $authors as $author ) {
Note: See TracChangeset for help on using the changeset viewer.