Skip to content

Conversation

@rebeccahum
Copy link
Contributor

@rebeccahum rebeccahum commented Dec 15, 2025

Description

This pull request enhances the job queue system by adding support for conditional updates on jobs, improving concurrency safety. The main change is that the update_jobs method now accepts additional WHERE conditions, allowing updates to be restricted based on job state (such as only updating jobs with a specific status). This helps prevent race conditions when multiple processes interact with the queue.

Changelog Description

Changed

  • Search: Fix race condition causing duplicate key errors in the search index queue by adding a status WHERE condition to prevent concurrent updates of the same job.

Pre-review checklist

Please make sure the items below have been covered before requesting a review:

  • This change works and has been tested locally or in Codespaces (or has an appropriate fallback).
  • This change works and has been tested on a sandbox.
  • This change has relevant unit tests (if applicable).
  • This change uses a rollout method to ease with deployment (if applicable - especially for large scale actions that require writes).
  • This change has relevant documentation additions / updates (if applicable).
  • I've created a changelog description that aligns with the provided examples.

Pre-deploy checklist

  • VIP staff: Ensure any alerts added/updated conform to internal standards (see internal documentation).

Steps to Test

@codecov
Copy link

codecov bot commented Dec 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 34.90%. Comparing base (2b21a3e) to head (3d747a7).

Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #6662      +/-   ##
=============================================
+ Coverage      34.85%   34.90%   +0.04%     
- Complexity      5029     5030       +1     
=============================================
  Files            295      295              
  Lines          20737    20739       +2     
=============================================
+ Hits            7228     7238      +10     
+ Misses         13509    13501       -8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rebeccahum rebeccahum marked this pull request as ready for review December 15, 2025 21:22
@rebeccahum rebeccahum requested a review from a team as a code owner December 15, 2025 21:22
Copilot AI review requested due to automatic review settings December 15, 2025 21:22
Copy link
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 adds race condition protection to the Search Queue's update_jobs() method by introducing an optional $where_conditions parameter. This allows atomic check-and-update operations to prevent concurrent processes from updating jobs that have already been processed by another process. The change is applied to checkout_jobs() and process_jobs() methods to ensure jobs are only updated when they're in the expected state.

Key Changes:

  • Added optional $where_conditions parameter to update_jobs() method for conditional updates
  • Updated checkout_jobs() to only update jobs that are in 'queued' status
  • Updated process_jobs() to only update jobs that are in 'scheduled' status

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
search/includes/classes/class-queue.php Added $where_conditions parameter to update_jobs() method and implemented WHERE clause logic; updated checkout_jobs() and process_jobs() to use conditional updates
tests/search/includes/classes/test-class-queue.php Added comprehensive test coverage for the new WHERE conditions functionality, including race condition scenarios and edge cases; updated existing test_process_jobs() to set jobs to 'scheduled' status before processing

@rebeccahum rebeccahum changed the title [PLTFRM-1860] Search: Use additional WHERE clause in update_jobs() to prevent race condition [PLTFRM-1860] Search: Use additional status WHERE clause in update_jobs() to prevent race condition Dec 15, 2025
…bs() to prevent race condition

Co-Authored-By: Copilot <[email protected]>
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants