Feat/batch sync content#231
Open
Kallyan01 wants to merge 11 commits into
Open
Conversation
…tion Scheduler and added db cleanup code
… asynchronous processing
…ement , improved sync UI
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces an Action Scheduler–backed job system to move Algolia sync/re-index work off the request thread, enabling batched async processing with progress tracking and a richer admin UI.
Changes:
- Add a new async job framework (AbstractJob, SyncJob, ReindexJob) plus a JobScheduler facade (Action Scheduler integration + job persistence).
- Update re-index and post-change indexing flows to schedule jobs instead of performing inline Algolia operations, and expose REST endpoints for job monitoring/retry/cancel.
- Extend the settings UI to show multi-site job progress, batch-level status, retry actions, and job history.
Reviewed changes
Copilot reviewed 18 out of 19 changed files in this pull request and generated 19 comments.
Show a summary per file
| File | Description |
|---|---|
| uninstall.php | Removes new scheduler/job state options & transients during uninstall. |
| phpstan/stubs/action-scheduler.php | Adds PHPStan stubs for Action Scheduler APIs/classes. |
| phpstan.neon.dist | Registers Action Scheduler stub scan file for static analysis. |
| onesearch.php | Loads Action Scheduler early from vendor if not already available. |
| inc/Modules/Search/Watcher.php | Schedules SyncJob on post transitions with inline fallback. |
| inc/Modules/Search/Index.php | Persists “settings initialized” across requests and deprecates sync reindex method. |
| inc/Modules/Scheduler/JobScheduler.php | Implements job lifecycle: schedule/execute/retry/cancel, storage, parent-child aggregation. |
| inc/Modules/Scheduler/Bootstrap.php | Registers job types and initializes scheduler on plugins_loaded. |
| inc/Modules/Rest/Search_Controller.php | Replaces reindex flow with ReindexJob orchestration + adds /re-index/status persistence. |
| inc/Modules/Rest/Job_Controller.php | Adds REST API for job listing, history, status proxying, retry, and cancel. |
| inc/Modules/Jobs/SyncJob.php | Implements batch post sync/delete to Algolia as a leaf job. |
| inc/Modules/Jobs/ReindexJob.php | Implements parent job that chunks posts into SyncJob children and dispatches runners. |
| inc/Modules/Jobs/Registry.php | Adds singleton job type registry. |
| inc/Modules/Jobs/AbstractJob.php | Adds job base model: status/progress/retry/serialization/relationships. |
| inc/Main.php | Registers Scheduler Bootstrap and Job REST controller. |
| composer.json | Adds woocommerce/action-scheduler dependency. |
| composer.lock | Locks Action Scheduler dependency and updates lock metadata. |
| assets/src/css/admin.scss | Adds styles for job progress UI, badges, and history panel. |
| assets/src/components/SiteIndexableEntities.tsx | Adds polling-based progress modal, retry UI, cancel UI, and history table. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
99
to
102
| /** | ||
| * Deletes transients. | ||
| */ | ||
| function delete_transients(): void { |
| 'post_ids' => [ (int) $post->ID ], | ||
| ] | ||
| ); | ||
| $job->set_group( 'onesearch_watcher' ); |
Comment on lines
+547
to
+551
| for ( $attempt = 0; $attempt < $max_tries; ++$attempt ) { | ||
| if ( set_transient( $lock_key, 1, 15 ) ) { | ||
| break; | ||
| } | ||
| usleep( 100000 + $attempt * 50000 ); // 100ms base, +50ms per attempt. |
| set_transient( $parent_key, $parent_data, self::TRANSIENT_EXPIRATION ); | ||
| } | ||
| } finally { | ||
| delete_transient( $lock_key ); |
Comment on lines
+190
to
+192
| public function schedule_recurring( AbstractJob $job, int $interval_seconds ): int { | ||
| $job->set_status( AbstractJob::STATUS_PENDING ); | ||
| $this->persist_job( $job ); |
Comment on lines
+723
to
+725
| role={ canExpand ? 'button' : undefined } | ||
| tabIndex={ canExpand ? 0 : undefined } | ||
| style={ { cursor: canExpand ? 'pointer' : 'default' } } |
Comment on lines
+31
to
+39
| public function register_routes(): void { | ||
| register_rest_route( | ||
| self::NAMESPACE, | ||
| '/jobs', | ||
| [ | ||
| [ | ||
| 'methods' => WP_REST_Server::READABLE, | ||
| 'callback' => [ $this, 'get_jobs' ], | ||
| 'permission_callback' => [ $this, 'check_job_read_permissions' ], |
Comment on lines
+115
to
+123
| // Get active reindex state for UI persistence across page refreshes. | ||
| register_rest_route( | ||
| self::NAMESPACE, | ||
| '/re-index/status', | ||
| [ | ||
| 'methods' => WP_REST_Server::READABLE, | ||
| 'callback' => [ $this, 'get_reindex_status' ], | ||
| 'permission_callback' => [ $this, 'check_api_permissions' ], | ||
| ] |
Comment on lines
+148
to
+154
| public function schedule( AbstractJob $job ): int { | ||
| if ( ! function_exists( 'as_enqueue_async_action' ) ) { | ||
| throw new \RuntimeException( 'Action Scheduler is not available. Install woocommerce/action-scheduler.' ); | ||
| } | ||
|
|
||
| $job->set_status( AbstractJob::STATUS_PENDING ); | ||
| $this->persist_job( $job ); |
Comment on lines
+125
to
+129
| // Batch-add to active index every 50 children to reduce DB writes. | ||
| if ( count( $pending_active_ids ) >= 50 ) { | ||
| $scheduler->add_many_to_active_index( $pending_active_ids ); | ||
| $pending_active_ids = []; | ||
| } |
…g on history table
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.
What
Why
Related Issue(s):
How
AI Disclosure
Testing Instructions
Screenshots
Additional Info
Checklist