[wp-trac] [WordPress Trac] #49693: Drop duplicate recurring cron events

WordPress Trac noreply at wordpress.org
Sat Jul 4 10:36:06 UTC 2020


#49693: Drop duplicate recurring cron events
-------------------------------------------------+-------------------------
 Reporter:  aidvu                                |       Owner:  whyisjake
     Type:  enhancement                          |      Status:  accepted
 Priority:  normal                               |   Milestone:  5.6
Component:  Cron API                             |     Version:  5.4
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests needs-      |     Focuses:
  testing needs-dev-note needs-refresh           |
-------------------------------------------------+-------------------------

Comment (by aidvu):

 > the current timing test is incomplete, a daily event can be added 500
 times if you start 500 days out and work back to tomorrow. If this is to
 be done, I'd rather do it properly by using the interval to determine a
 remainder, I recall some issues with single events due the the imprecise
 logic it had until recently

 This is true. I went with the idea from this comment:
 https://core.trac.wordpress.org/ticket/49693#comment:12. Boils down to,
 make a safeguard so that situations that usually occur (adding events on
 every pageload because of a typo in the event name wouldn't break WP).
 Also, even if you did manage to add 500 duplicate daily events, the
 reschedule would drop them.

 I also wanted to keep the logic simple. In a 24 hour interval, max
 duplicate recurring events is 24.

 > min_timestamp and max_timestamp will need the additional calculations
 for events scheduled around time(), see the other cron functions for
 these.

 Can check.

 > Create a filter for $allowed_occurrences and pass the event details
 > $allowed_occurrences === true (or another such value) to allow for
 unlimited occurrences if a plugin filters for it.


 Makes sense.

 > In the tests, rather than $max_events = DAY_IN_SECONDS /
 HOUR_IN_SECONDS;, etc, put in the expected values (24, etc) -- otherwise
 you're testing the code by running the code, which will always pass.

 Kk.

 > Additional tests will be needed to ensure the same hook with different
 arguments or intervals are not considered duplicates

 Sure, like filling in the max occurrences and then switching the params.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/49693#comment:21>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list