Skip to content

feat: throttle the sync check, index-friendly query, filters and docs (1.1.0) - #13

Merged
herewithme merged 1 commit into
masterfrom
feat/sync-check-hardening
Oct 16, 2026
Merged

herewithme merged 1 commit into
masterfrom
feat/sync-check-hardening

Conversation

@herewithme

Copy link
Copy Markdown
Member

Context

Review of the plugin after 1.0.3. The code was safe (prepared query, no user input, wp_publish_post is idempotent) but the synchronous mode had a real cost: on every request where WP-Cron is spawned by page loads, wp_loaded ran SELECT ID FROM wp_posts WHERE post_status = 'future' AND post_date <= now. The posts table has no index starting with post_status, so that was a full scan per request on large sites.

Changes

Code (beapi-missed-schedule.php)

  • Throttle: the wp_loaded check runs at most once per minute, locked by a transient (object cache when available, options table otherwise). Skipped during cron requests. Filter beapi_missed_schedule_sync_throttle, 0 restores the old behaviour.
  • Query: filters on the registered post types so MySQL uses type_status_date, and compares post_date_gmt with GMT now, as check_and_publish_future_post() does. The phpcs:ignore covers the %s placeholder list built with array_fill().
  • Publication: goes through the core check_and_publish_future_post() callback (same status and date checks as a normal scheduled publication). The orphaned publish_future_post single event is cleared only once the post is actually published, so a reschedule by core is never dropped.
  • Cron registration moved from file load to init. Event hook and schedule names are constants; the schedule key is now beapi-missed-schedule instead of the generic 5-minutes.
  • Filters: 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.
  • Removed the two TODO commented lines, translatable schedule label, Text Domain header filled, empty Domain Path removed.
  • Requirements raised to WordPress 4.9 and PHP 7.4 (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.md rewritten: 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, not LICENSE.md).
  • CHANGELOG.md rebuilt from the tags and PRs.
  • phpcs.xml: ruleset renamed from the copy-pasted ContentSyncFusion, testVersion 7.4-, deprecated text_domain property syntax fixed (PHPCS 4 would reject it).
  • .distignore / .gitattributes: stale psalm.xml, old-bitbucket-pipelines.yml and the LICENCE typo (which never excluded anything) removed.
  • CONTRIBUTING.md said GPLv3 while the plugin is GPLv2 or later.

Not changed

  • No uninstall routine: a mu-plugin has none. Documented instead.
  • Behaviour with DISABLE_WP_CRON is unchanged: WP-Cron event only, no sync check.

Checks

  • composer cs passes locally on PHP 8.4, php -l clean, composer validate OK.
  • Not tested on a live site: the query and the throttle deserve a run on a staging with a scheduled post in the past.

After merge

Tag 1.1.0 on master and publish the release with the changelog entry.

🤖 Generated with Claude Code

- 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>
@herewithme
herewithme merged commit 68c3121 into master Oct 16, 2026
3 checks passed
@herewithme
herewithme deleted the feat/sync-check-hardening branch October 16, 2026 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant