-
Notifications
You must be signed in to change notification settings - Fork 114
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
Add a faster and simpler version of as_next_scheduled_action() #688
Add a faster and simpler version of as_next_scheduled_action() #688
Conversation
Just noting that this has come up before, including in WC core usage. The previous recommendation was to add the transient / caching in the calling code, both because That doesn't mean AS can't offer a new function with a transient or other cache to improve performance, and this issue has come up enough times that it would be worth doing that. It looks like the introduction of There's still an issue of how long to set the cache for, but even a short lived expiry, like 1-2 minutes, could provide significant performance improvements by default, and any sites that want a longer expiry still have the option to use |
IMO leaving caching to the caller is perfectly acceptable and preferable: If you implement caching into the function, then you also have to clear the cached item when an action is scheduled, which adds complexity. IMO: intro the new function with a fast query, and let the caller do anything else. |
I'm not familiar with any use cases where the expiration time is used like this. Every time I've used or seen
I don't think there will be much of a measurable benefit between the proposed Perhaps there's a role for persistent object caching here. I think cache invalidation will be important and could be difficult. I guess it would need to potentially invalidate the cache after every action run and when every action is created, updated or deleted. I tend to agree with @crstauf that the caller should handle transient-style caching. |
This looks good, thank you @danielbitzer! We should go ahead and add to
Less sure about this (though it's "legacy", both stores have maintained feature parity up until now, afaik), but will start a discussion and let you know what we come up with 👍 |
Would it make sense to have an index that helps optimize for this? |
Following up on this once more: yes, we'd need a matching change there (even if in that context it exists purely for compatibility reasons, vs a performance boost). |
mysql will automatically optmize for single `IN` value vs `=` for us
I've made a few changes:
I found I had to run |
Autoload seems to fail with Github actions
@barryhughes thanks for reviewing! I've updated everything based on your feedback. |
Also improve doc blocks
I've just documented the query params docs for query |
This is great, left some thoughts in (related) PR 752—figured it made sense to work through that first since it targets this branch. |
And revert deprecation of ‘find_action’.
Shortcut method to get a single action from 'query_actions'.
…n-method Replace uses of `\ActionScheduler_Store::find_actions` with `\ActionScheduler_Store::query_actions`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent stuff!
Updated the PR description to add a changelog entry, feel free to revise if needed. |
as_next_scheduled_action()
is the standard way that plugins can determine if a specific action is currently upcoming/scheduled but it could be optimized.For example, the Facebook for WooCommerce plugin performs a check on every
init
hook to determine if thewc_facebook_regenerate_feed
recurring action is scheduled. We've had a report that this is slowing down sites and arguable we should be storing this as a transient.But after looking into
as_next_scheduled_action()
I realized it performs up to 4 queries to gain additional information about the scheduled action while most use cases I see in plugins simply need a boolean response. My proposal is to introduce aas_has_scheduled_action()
function that is similar toas_next_scheduled_action()
but is optimized for this common use case of checking that a specific action is scheduled.Advantages
ORDER BY scheduled_date_gmt
clause which has been reported to significantly slow down queries, see Speed up clean up and batch selects. #678 and large actions table results in non-performant query facebook-for-woocommerce#1796 (comment)Existing as_next_scheduled_action() queries:
New as_has_scheduled_action() query:
Next steps
Changelog