Making WordPress.org

Changeset 14714


Ignore:
Timestamp:
03/13/2026 08:03:05 PM (4 weeks ago)
Author:
obenland
Message:

WP.org Abilities: Optimize get_feedback() to short-circuit on latest reviewer message.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-abilities/plugins/plugin-directory/tools/class-get-plugin-status.php

    r14712 r14714  
    280280            }
    281281
     282            // When only the latest reviewer message is needed, find it directly.
     283            if ( ! $full_history ) {
     284                foreach ( $threads as $thread ) {
     285                    if ( in_array( $thread->type ?? '', array( 'reply', 'message' ), true ) ) {
     286                        $body = $thread->body ?? '';
     287                        if ( $body ) {
     288                            $body = self::html_to_text( $body );
     289                            $body = self::strip_boilerplate( $body );
     290                        }
     291
     292                        return array(
     293                            array(
     294                                'from' => 'reviewer',
     295                                // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- HelpScout API property.
     296                                'date' => $thread->createdAt ?? '',
     297                                'body' => $body,
     298                            ),
     299                        );
     300                    }
     301                }
     302
     303                // No reviewer message found in this email, try next.
     304                continue;
     305            }
     306
     307            // Full history: process all threads.
    282308            foreach ( $threads as $thread ) {
    283309                // Skip internal notes and system events — only include customer and agent messages.
     
    302328
    303329        // Return in chronological order (oldest first) so it reads as a conversation.
    304         $feedback = array_reverse( $feedback );
    305 
    306         // By default, return only the most recent reviewer message.
    307         if ( ! $full_history ) {
    308             for ( $i = count( $feedback ) - 1; $i >= 0; $i-- ) {
    309                 if ( 'reviewer' === $feedback[ $i ]['from'] ) {
    310                     return array( $feedback[ $i ] );
    311                 }
    312             }
    313         }
    314 
    315         return $feedback;
     330        return array_reverse( $feedback );
    316331    }
    317332
Note: See TracChangeset for help on using the changeset viewer.