Skip to content

[13.x] Cache database queue lock type to avoid repeated PDO version detection#59348

Draft
JoshSalway wants to merge 3 commits intolaravel:13.xfrom
JoshSalway:fix/cache-db-queue-lock-for-popping
Draft

[13.x] Cache database queue lock type to avoid repeated PDO version detection#59348
JoshSalway wants to merge 3 commits intolaravel:13.xfrom
JoshSalway:fix/cache-db-queue-lock-for-popping

Conversation

@JoshSalway
Copy link
Copy Markdown
Contributor

@JoshSalway JoshSalway commented Mar 24, 2026

Fixes #59350

Summary

getLockForPopping() makes 2 PDO attribute calls, creates Stringable objects, parses version strings, and runs version_compare() on every single job pop. The DB engine and version never change during a worker's lifetime, so this work is redundant after the first call.

Problem

Every call to DatabaseQueue::pop() triggers getLockForPopping(), which:

  1. Calls PDO::getAttribute(ATTR_DRIVER_NAME)
  2. Calls PDO::getAttribute(ATTR_SERVER_VERSION)
  3. Creates a Stringable instance
  4. Runs version_compare()

For high-throughput queue workers processing thousands of jobs, this adds up to significant unnecessary overhead.

Solution

Cache the computed lock type in an instance property after the first call. Subsequent calls return the cached value directly, eliminating repeated PDO calls and string parsing for the lifetime of the worker process.

Before

Every pop() call triggers full PDO version detection and string comparison, regardless of how many times it has already been computed.

After

PDO version detection runs once on the first pop(), then the cached lock type is returned for all subsequent calls.

Test plan

  • Existing database queue test suite passes
  • Queue workers correctly detect lock type on first pop
  • Verified on MySQL, PostgreSQL, and SQLite drivers

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

Ensures that getPdo() and getAttribute() are only called once across
multiple getLockForPopping() invocations, validating the lock type
caching behavior.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JoshSalway JoshSalway changed the title Cache database queue lock type to avoid repeated PDO version detection [13.x] Cache database queue lock type to avoid repeated PDO version detection Mar 28, 2026
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.

DatabaseQueue::getLockForPopping() re-detects DB version on every job pop

1 participant