Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#45976 closed defect (bug) (fixed)

Move logic to find next event from `wp_next_scheduled()` to `wp_get_scheduled_event()`.

Reported by: peterwilsoncc's profile peterwilsoncc Owned by: peterwilsoncc's profile peterwilsoncc
Milestone: 5.1 Priority: normal
Severity: normal Version: 5.1
Component: Cron API Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

The new function for 5.1 wp_get_scheduled_event() accepts the timestamp as an optional argument. If no timestamp is specified the next scheduled event is returned.

If no timestamp is specified, it current makes use of wp_next_scheduled() to determine the timestamp of the next event. This results in running code to get the cron array and determine the key twice.

The logic could be reversed, wp_get_scheduled_event() could determine the next event and wp_next_scheduled() make use of that function if an event is returned.

This will allow the pre_next_scheduled and next_scheduled filters to be deprecated. If the change is made prior to WP 5.1's release, they can be removed.

Attachments (3)

45976.diff (4.0 KB) - added by peterwilsoncc 6 years ago.
45976.2.diff (8.2 KB) - added by peterwilsoncc 6 years ago.
45976.3.diff (9.0 KB) - added by peterwilsoncc 6 years ago.

Download all attachments as: .zip

Change History (9)

@peterwilsoncc
6 years ago

#1 @pento
6 years ago

  • Milestone changed from Awaiting Review to 5.1

#2 @peterwilsoncc
6 years ago

  • Owner set to peterwilsoncc
  • Status changed from new to assigned

#3 @peterwilsoncc
6 years ago

In 45976.2.diff

  • Unit tests for wp_get_scheduled_event()
  • Remove tests for removed filter
  • bitwise & replaced with && inside condition

#4 @peterwilsoncc
6 years ago

  • Keywords has-unit-tests added

return false checks added in 45976.3.diff.

#5 @desrosj
6 years ago

This makes sense and 45976.3.diff looks good. Tested well in my sandbox.

#6 @peterwilsoncc
6 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 44693:

Cron: Move logic for finding the next event's timestamp.

Moves the logic for determining when an event will next run from wp_next_scheduled() to wp_get_scheduled_event().

This improves the performance of wp_get_scheduled_event() by avoiding duplicate function calls and object cache hits.

Props peterwilsoncc.
Fixes #45976.

Note: See TracTickets for help on using tickets.