humanmade / humanmade/altis-cloud
Avoid Cavalcade lookups on front-end requests
- Dominant language
- PHP
- Stars
- 9
- Forks
- 2
- Avg merge
- 6d 1h
- Merged PRs (30d)
- 23
Description
Per this issue on the Cavalcade repo when db latency is a factor the common pattern of checking for and scheduling cron jobs is often done on `init`. WP core does this as well many 3rd party plugins etc...
- https://github.com/humanmade/Cavalcade/issues/117
In theory we could avoid this altogether using the preflight filter to limit these checks to the admin only, provided they are added during the `init` hook:
```php
add_filter( 'pre_get_scheduled_event', function ( $pre ) {
if ( ! doing_action( 'init' ) || is_admin() ) {
return $pre;
}
return true;
}, 1 );
```
Events will still be scheduled but on admin requests only.
This would cause issues if plugins are adding events on the frontend using the `init` hook based on user interactions and `$_GET` or `$_POST` parameters, although that would be far more likely dealt with not on the `init` hook.
This approach seems safe to me, especially if we also check that `$_POST` is empty. Would be great to get some additional input and feedback though.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.