-
Notifications
You must be signed in to change notification settings - Fork 5
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
Fix bug with Auto-Cache Engine cron disappearing in some scenarios #197
Conversation
@jaswsinc A review, please. Here's what I did to fix wpsharks/comet-cache#613 and why:
|
Looks great Raam! You might also consider adding this block to the |
After reviewing my own comment here: wpsharks/comet-cache#613 (comment) I suggest that we also validate the configured cache cleanup schedule before we attempt to use it. In addition, the |
@jaswsinc writes...
Do you mean at the start of running the hooked function (e.g., |
Oh, I think you're referring to validating I see the intention with that line was to prevent unnecessarily calling So I'm thinking we need to validate |
I think this will do it: 861cc45 |
I'm not seeing why this would be necessary given my last commit (861cc45). Am I missing something? |
@jaswsinc Well, if we created a hash of |
Exactly, yes.
Right. To only reschedule when necessary.
Right, exactly. And, whatever we do there should be optimized in every way possible since it will run on every page view. So our strategy should be one that reduces the amount of work it takes to run a quick check. Calling <?php
sha1(serialize(wp_get_schedules())); It might help if we break apart those bits of information into separate option keys, because there are enough of them now that it's beginning to create some unnecessary complexity. We are trying to stuff everything into 'crons_setup' => '0', // A timestamp when last set up.
'crons_setup_on_namesapce' => '', // The namespace on which they were set up.
'crons_setup_with_cache_cleanup_schedule' => '', // The cleanup schedule selected by site owner during last setup.
'crons_setup_on_wp_with_schedules' => '', // A sha1 hash of `wp_get_schedules()` With those new option keys we can have something easier to read.... if ($this->options['crons_setup'] < 1439005906
|| $this->options['crons_setup_on_namespace'] !== __NAMESPACE__
|| $this->options['crons_setup_with_cache_cleanup_schedule'] !== $this->options['cache_cleanup_schedule']
|| $this->options['crons_setup_on_wp_with_schedules'] !== sha1(serialize(wp_get_schedules()))) {
// ... Recreate.
} One possible problem with this, is the sequence of events with respect to us calling upon Even if we attached ZenCache to the So for that reason, you might think about moving this set of checks against the add_action('init', array($this, 'checkCronSetup'), PHP_INT_MAX); |
We have this file where we could move that entire CRON-related block: |
Already done. 😄 About to push a commit. |
Totally agree. I started to rewrite the code to stuff the hash into the existing
Yep, I totally agree again. A separate method is exactly what's in order. |
@jaswsinc Thanks for the great pointers and ideas for how to improve this. :-) See 7a652a7 I ran some tests to confirm things are behaving as expected. One thing to point out is my inclusion of |
This bug in your example had me scratching my head for several minutes when things failed during my initial tests (my fault for copying/pasting, haha):
|
🙈 Sorry!
Outstanding! That looks so much better organized now too.
Otherwise it looks perfect to me. |
I love the |
Done. Thanks! f67b8b4
Awesome. Thanks so much for the reviews! |
See wpsharks/comet-cache#613