From 42d3773de9b9c23da7acdee4b20ed9c3b0a00ac8 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Fri, 9 Sep 2022 01:51:52 +0000 Subject: [PATCH] Cron API: Remove unnecessary optimization getting ready events. Remove the check for future events prior iterating the array of crons in `wp_get_ready_cron_jobs()`. If there are no ready events, the `foreach` loop will break on the first iteration so the optimization is not required. As WordPress Core adds a number of events by default, accounting for an empty array is not required in most instances. Props lev0, jrf, SergeyBiryukov. Fixes #56092. git-svn-id: https://develop.svn.wordpress.org/trunk@54110 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/cron.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/cron.php b/src/wp-includes/cron.php index f04088061a..9e83942f70 100644 --- a/src/wp-includes/cron.php +++ b/src/wp-includes/cron.php @@ -1122,23 +1122,20 @@ function wp_get_ready_cron_jobs() { * to continue using results from _get_cron_array(). */ $pre = apply_filters( 'pre_get_ready_cron_jobs', null ); + if ( null !== $pre ) { return $pre; } $crons = _get_cron_array(); - $gmt_time = microtime( true ); - $keys = array_keys( $crons ); - if ( isset( $keys[0] ) && $keys[0] > $gmt_time ) { - return array(); - } - $results = array(); + foreach ( $crons as $timestamp => $cronhooks ) { if ( $timestamp > $gmt_time ) { break; } + $results[ $timestamp ] = $cronhooks; }