Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update async publish actions #1999

Merged
merged 3 commits into from
Feb 22, 2021
Merged

Conversation

WPprodigy
Copy link
Contributor

@WPprodigy WPprodigy commented Feb 22, 2021

Description

Prevents a large number of cron jobs from being registered, unless they are truly needed.

This PR includes 3 steps:

  1. Track the usage of this feature, to better help make future decisions.
  2. Remove the two "default" offloads.
  3. Only register the cron job when the hooks are being used.

Some Considerations

For 2, by removing the two default offloads - the track_publish_post() and _publish_post_hook() logic will now happen synchronously when a post is published, the effects of which quite minimal here. One additional note is that track_publish_post() would have technically only have been run when the async cron job was truly added based on the should_offload() default logic, meaning it was also excluded from being run on new posts created during cron, cli, and xmlrpc. This could be replicated if desired by checking for more than just WP_IMPORTING in this function.

For 3, if one of these hooks was for some reason only conditionally registered underneath cli/cron checks specifically - then we'd possibly be missing out that the cron needed to be registered. This is quite unlikely though, and I have searched for all use cases I can find and the few out there do not fall into this trap. But if desired, we could move step 3 into a future PR for after we have more usage information.

Changelog Description

Plugin Updated: Async Publish Actions

This change removes the creation of async post publish cron jobs if they are not being utilized. If the relevant hooks are in use, the cron jobs will continue to be created normally.

Checklist

Please make sure the items below have been covered before requesting a review:

  • This change works and has been tested locally (or has an appropriate fallback).
  • This change works and has been tested on a Go sandbox.
  • This change has relevant unit tests (if applicable).
  • n/a This change has relevant documentation additions / updates (if applicable).
  • I've created a changelog description that aligns with the provided examples.

Documentation: https://docs.wpvip.com/how-tos/code-quality-and-best-practices/write-asynchronous-publishing-actions/. Will be updated when applicable.

Steps to Test

  1. Check out PR.
  2. Create and publish a new post.
  3. Quickly run wp cron-control events list and notice how no wpcom_vip_async_transition_post_status job was added.
  4. Now add something like the below, and note how a cron job is registered and run after publishing a post:
add_action( 'async_transition_post_status', function() {
	error_log('hello');
} );

For phpunit, phpunit --group async-publish-actions to skip to the relevant parts.

Only schedule the cron job if it’s needed
@WPprodigy WPprodigy requested a review from a team as a code owner February 22, 2021 22:07
@WPprodigy WPprodigy marked this pull request as draft February 22, 2021 22:11
None of the other methods had it in this file 😬
@WPprodigy WPprodigy marked this pull request as ready for review February 22, 2021 23:06
@nickdaugherty nickdaugherty merged commit 308f52d into master Feb 22, 2021
@nickdaugherty nickdaugherty deleted the update/async-publish-actions branch February 22, 2021 23:44
@nickdaugherty
Copy link
Contributor

r1404-stacks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants