Skip to content

Avoid Cavalcade lookups on front-end requests #702

@roborourke

Description

@roborourke

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...

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions