humanmade / humanmade/Cavalcade
Cannot unschedule more than 100 events with a given hook
- Dominant language
- PHP
- Stars
- 542
- Forks
- 48
- PR merge metrics
- No merged PRs in 30d
Description
Deleting all events with a given hook via `wp cron event unschedule ` or `wp_unschedule_hook( )` will only delete a maximum of 100 events. If there are more than 100 events with that hook then the remainder will not be deleted and the command will need to be run multiple times.
This problem was identified on a site with a runaway process that had scheduled thousands of events with the same hook name but different parameters. Unscheduling the events only unscheduled 100 at a time.
This is caused by [the `\HM\Cavalcade\Plugin\Connector\pre_clear_scheduled_hook` function](https://github.com/humanmade/Cavalcade/blob/87ff25e5f6a99b7d7c6626f966adceb086186c73/inc/connector/namespace.php#L304) that's hooked into `pre_clear_scheduled_hook` which queries for a maximum of 100 jobs.
The fix would be to either repeat this query in a loop until there are no more matches, or to remove the `limit` on the query, although the latter risks exhausting memory if there's an exceptionally high number of jobs with that hook.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.