Repository navigation
feat: throttle the sync check, index-friendly query, filters and docs (1.1.0) - #13
Merged
Merged
Conversation
- Throttle the wp_loaded check to one run per minute with a transient and skip it during cron requests: it used to scan wp_posts on every request when WP-Cron was spawned by page loads. - Filter the query on post type so MySQL uses the type_status_date index, and compare post_date_gmt with GMT now like core does. - Publish through check_and_publish_future_post() and only clear the publish_future_post single event once the post is published. - Register the WP-Cron event on init instead of at file load. - Add beapi_missed_schedule_limit, _interval and _sync_throttle filters. - Translatable schedule label, text domain set, requirements raised to WordPress 4.9 and PHP 7.4, version 1.1.0. - README rewritten, CHANGELOG.md added, phpcs.xml / .distignore / .gitattributes / CONTRIBUTING cleaned up. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Review of the plugin after 1.0.3. The code was safe (prepared query, no user input,
wp_publish_postis idempotent) but the synchronous mode had a real cost: on every request where WP-Cron is spawned by page loads,wp_loadedranSELECT ID FROM wp_posts WHERE post_status = 'future' AND post_date <= now. The posts table has no index starting withpost_status, so that was a full scan per request on large sites.Changes
Code (
beapi-missed-schedule.php)wp_loadedcheck runs at most once per minute, locked by a transient (object cache when available, options table otherwise). Skipped during cron requests. Filterbeapi_missed_schedule_sync_throttle,0restores the old behaviour.type_status_date, and comparespost_date_gmtwith GMT now, ascheck_and_publish_future_post()does. Thephpcs:ignorecovers the%splaceholder list built witharray_fill().check_and_publish_future_post()callback (same status and date checks as a normal scheduled publication). The orphanedpublish_future_postsingle event is cleared only once the post is actually published, so a reschedule by core is never dropped.init. Event hook and schedule names are constants; the schedule key is nowbeapi-missed-scheduleinstead of the generic5-minutes.beapi_missed_schedule_limit(10),beapi_missed_schedule_interval(300 s),beapi_missed_schedule_sync_throttle(60 s). The README said the plugin had no hook.TODOcommented lines, translatable schedule label,Text Domainheader filled, emptyDomain Pathremoved.wp_doing_cron()needs 4.8; the dev tooling already needed PHP 7.2+ and CI runs 8.2 to 8.4). To validate: it is the only functional change for existing installs.Docs and tooling
README.mdrewritten: how the two mechanisms work, constants, filters table, cleanup of the cron event when the mu-plugin is removed (wp cron event delete beapi_missed_scheduled_event), license link fixed (LICENSE, notLICENSE.md).CHANGELOG.mdrebuilt from the tags and PRs.phpcs.xml: ruleset renamed from the copy-pastedContentSyncFusion,testVersion 7.4-, deprecatedtext_domainproperty syntax fixed (PHPCS 4 would reject it)..distignore/.gitattributes: stalepsalm.xml,old-bitbucket-pipelines.ymland theLICENCEtypo (which never excluded anything) removed.CONTRIBUTING.mdsaid GPLv3 while the plugin is GPLv2 or later.Not changed
DISABLE_WP_CRONis unchanged: WP-Cron event only, no sync check.Checks
composer cspasses locally on PHP 8.4,php -lclean,composer validateOK.After merge
Tag
1.1.0onmasterand publish the release with the changelog entry.🤖 Generated with Claude Code