Skip to content

Feat/batch sync content#231

Open
Kallyan01 wants to merge 11 commits into
mainfrom
feat/batch-sync-content
Open

Feat/batch sync content#231
Kallyan01 wants to merge 11 commits into
mainfrom
feat/batch-sync-content

Conversation

@Kallyan01
Copy link
Copy Markdown
Collaborator

@Kallyan01 Kallyan01 commented Jun 1, 2026

What

Why

Related Issue(s):

How

AI Disclosure

Testing Instructions

Screenshots

Additional Info

Checklist

  • I have read the Contribution Guidelines.
  • I have read the Development Guidelines.
  • I have added necessary tests to cover my changes.
  • I have updated the project documentation as needed.
  • My code has detailed inline documentation.
  • My code is tested to the best of my abilities.
  • My code passes all lints, tests, and checks.
Open WordPress Playground Preview

@Kallyan01 Kallyan01 marked this pull request as ready for review June 2, 2026 11:40
Copilot AI review requested due to automatic review settings June 2, 2026 11:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 thread uninstall.php Outdated
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 = [];
}
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.

2 participants