Skip to content

Conversation

@GaryJones
Copy link
Contributor

When a syn_site post or syn_sitegroup term is saved or deleted, the system previously triggered an immediate synchronous refresh of pull jobs. This approach becomes problematic when many sites are configured, as the refresh operation can take considerable time and lead to timeout errors, making it impossible to add or edit sites.

The root cause is that refresh_pull_jobs() iterates through all configured sites and performs API calls, which becomes increasingly expensive as the number of sites grows. Running this synchronously within the save/delete request lifecycle means the HTTP request must wait for all these operations to complete.

This change defers the refresh operation to a background cron event scheduled 60 seconds in the future. The implementation includes debouncing through a transient to prevent duplicate scheduling when multiple sites are modified in quick succession. The transient expires after 2 minutes, whilst any existing scheduled event is cleared before scheduling a new one to ensure only one refresh runs.

The solution maintains data consistency by ensuring the refresh still occurs, just asynchronously rather than blocking the HTTP request. This approach is particularly effective for bulk operations where multiple sites might be saved in quick succession—rather than triggering multiple expensive refresh operations, they are debounced into a single deferred event.

Unit tests verify the debouncing logic, event scheduling, transient management, and correct integration with the existing site and site group change handlers.

Fixes #86

Addresses timeout issues when adding or editing syndication sites in
installations with many configured syndication sites. The synchronous
refresh_pull_jobs() operation becomes prohibitively expensive at scale,
causing requests to timeout during site administration.

This change introduces deferred background processing via WordPress cron.
When sites or site groups are modified, instead of immediately clearing
and rescheduling all pull jobs, the operation is deferred to a one-time
cron event scheduled 60 seconds in the future. A transient-based debounce
mechanism prevents duplicate scheduling when multiple rapid changes occur.

The solution maintains functional correctness whilst eliminating timeout
issues by moving the expensive operation out of the request lifecycle.

Fixes #86
@GaryJones GaryJones requested a review from a team as a code owner January 3, 2026 21:49
@GaryJones GaryJones self-assigned this Jan 3, 2026
@GaryJones GaryJones added the type: bug Something isn't working label Jan 3, 2026
@GaryJones GaryJones added this to the 2.2.0 milestone Jan 3, 2026
@GaryJones GaryJones merged commit dcc08a5 into develop Jan 4, 2026
8 checks passed
@GaryJones GaryJones deleted the fix/86-timeout-adding-editing-site branch January 4, 2026 15:20
@GaryJones GaryJones mentioned this pull request Jan 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Timeout issues when adding/editing a site

2 participants