Repository navigation
Conversation
0fc64ea to
ba16f73
Compare
There was a problem hiding this comment.
Pull request overview
Adds a scheduler to WP Super Cache’s Preload feature so admins can run preloading either on a repeating timer or at a specific clock time (similar to the Garbage Collection scheduler).
Changes:
- Introduces new Preload scheduling settings (
intervalvstime, scheduled time, cron interval). - Updates
wpsc_preload_settings()andwp_cron_preload_cache()to schedule either single events (timer) or recurring cron events (clock). - Adds Preload UI controls for selecting Timer/Clock mode and configuring time + interval.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
wp-cache.php |
Implements new schedule settings persistence and cron scheduling behavior for interval/time modes. |
wp-cache-config-sample.php |
Adds sample defaults for the new preload scheduling variables. |
partials/preload.php |
Adds the Scheduler UI (Timer/Clock) to the Preload settings tab. |
Comments suppressed due to low confidence (1)
wp-cache.php:3720
- In time-based scheduling mode,
$cache_max_timeis still derived from$wp_cache_preload_interval(minutes). If the user switches to Clock mode but leaves the timer value at a small/default value, the cleanup step may delete cached files much sooner than the next scheduled preload run. Consider deriving$cache_max_timefrom the Clock interval (e.g., the selected cron schedule duration) when$preload_schedule_type === 'time'.
global $file_prefix, $cache_max_time;
if ( $wp_cache_preload_interval > 0 ) {
$cache_max_time = (int)$wp_cache_preload_interval * 60; // fool the GC into expiring really old files
} else {
$cache_max_time = 86400; // fool the GC into expiring really old files
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Display input time in the site's configured timezone instead of UTC. - Convert the entered HH:MM to the next UTC timestamp via a shared helper, advancing to the next day when the chosen time has already passed today. - Fix a stray/malformed preg_match line left over from the previous commit and tighten HH:MM validation to reject out-of-range values.
Reviewed the scheduling state machine, since converting ContextTwo cron hooks both fire Blocker
wp_unschedule_event( $next_full_preload, 'wp_cache_full_preload_hook' );
wp_clear_scheduled_hook( 'wp_cache_full_preload_hook' ); // handles single + recurringThe Cleanup (not a blocker)End-of-run reschedule block in "time" mode is dead code — in Warnings
Not issuesTimezone handling in SuggestionThe root cause is that "convert to recurring" wasn't applied uniformly across the schedule / cancel / enable paths. Consider centralizing into a single |
…edule # Conflicts: # wp-cache.php
Cancel now clears every occurrence of both preload hooks, so a Clock-mode schedule no longer survives "Cancel Cache Preload" when a one-off preload is also queued. Clock scheduling falls back to "daily" when the saved cron schedule is no longer registered, and the cleanup after a Clock-mode run expires files on the Clock interval instead of the unused Timer value.
Saving the Preload tab no longer replaces the pending event when nothing that drives it changed. Configs written before Clock mode lack the new settings, so the first save after an upgrade used to clear the Timer event and leave a stop flag that made the next run abort. A forced reschedule now writes the stop flag only while a run is in progress, Clock fields only count in Clock mode, and Clock schedules shorter than the minimum preload interval are rejected. A one-off run no longer re-arms the Clock schedule when Preload mode is off.
|
Thanks for the careful look. I merged trunk first, so this code now lives in
13b1669 also makes a save reschedule only when the effective schedule changes, and rejects Clock intervals shorter than the minimum preload interval. |
Summary
wp_cron_preload_cache()andwpsc_preload_settings()to handle both interval and time-based schedulingThis allows server administrators to schedule resource-intensive preloading during off-peak hours (e.g., 03:00 AM) to minimize impact on site performance.
Originally proposed by @zeus2611 in Automattic/jetpack#47018.
Fixes #1017
Test plan
wp_cache_preload_hookis scheduled at the correct time (e.g., via WP Crontrol)