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
This commit is contained in:
Peter Wilson 2022-09-09 01:51:52 +00:00
parent 6be371b4ec
commit 42d3773de9

View File

@ -1122,23 +1122,20 @@ function wp_get_ready_cron_jobs() {
* to continue using results from _get_cron_array(). * to continue using results from _get_cron_array().
*/ */
$pre = apply_filters( 'pre_get_ready_cron_jobs', null ); $pre = apply_filters( 'pre_get_ready_cron_jobs', null );
if ( null !== $pre ) { if ( null !== $pre ) {
return $pre; return $pre;
} }
$crons = _get_cron_array(); $crons = _get_cron_array();
$gmt_time = microtime( true ); $gmt_time = microtime( true );
$keys = array_keys( $crons );
if ( isset( $keys[0] ) && $keys[0] > $gmt_time ) {
return array();
}
$results = array(); $results = array();
foreach ( $crons as $timestamp => $cronhooks ) { foreach ( $crons as $timestamp => $cronhooks ) {
if ( $timestamp > $gmt_time ) { if ( $timestamp > $gmt_time ) {
break; break;
} }
$results[ $timestamp ] = $cronhooks; $results[ $timestamp ] = $cronhooks;
} }