Repository navigation
fix: bound the in-memory attachment ID cache - #1192
Merged
Merged
Conversation
The request-local map in Optml_Attachment_Cache kept every distinct URL looked up during a request, including misses, with no limit. It now keeps at most 2000 URLs and drops the older half when full; dropped URLs are still served from the persistent cache (transient or object cache). Refs #1139 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MEXWtYdE6e3ALYtqtP8j2p
pirate-bot
requested changes
Oct 20, 2026
Collaborator
There was a problem hiding this comment.
🟡 Changes requested
The cap works, but no added test covers the cache-miss path, and the remember() value type is wrong.
Validation details
- Files reviewed: 2/2 changed files. The "Caps and limits: Realistic volume" row stayed unchecked.
- PHPUnit 9.6.22 on PHP 8.3.35 ran the new tests at HEAD:
cd /repo; set -o pipefail; timeout 280 vendor/bin/phpunit --do-not-cache-result --filter 'Test_Attachment_Cache::' 2>&1 …(run R5, exit 0) - With the cache-miss path reverted, the new tests still pass:
set -o pipefail; cd /workspace/checks/C6/mutant && rm /var/www/html/wp-content/plugins/optimole-wp && (timeout 300 vendo…printedOK (3 tests, 8 assertions)(run R8) - A miss-only control test catches that revert: `set -o pipefail; cd /workspace/checks/C6/mutant && cat > tests/test-c6-control.php <<'EOF'
Untested areas
- Caps and limits: Realistic volume. No data shows how many distinct URLs real pages hold. Issue #1139 says the telemetry lacks it. - Jest and Playwright suites were not run. The change does not touch them.Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MEXWtYdE6e3ALYtqtP8j2p
pirate-bot
approved these changes
Oct 20, 2026
Collaborator
There was a problem hiding this comment.
🟢 Approved
The PR passes: both earlier findings are fixed, and the new commit adds no new problem.
Validation details
- Files reviewed: 2/2 changed files. The "Caps and limits: Realistic volume" question stayed unchecked.
- PHPUnit 9.6.22 on PHP 8.3.35 ran the cache tests at HEAD:
cd /repo && set -o pipefail; timeout 280 vendor/bin/phpunit --do-not-cache-result --filter 'Test_Attachment_Cache::' 2>&…printedOK (3 tests, 7 assertions)(run R2) - A copy with only the cache-miss write reverted fails the new test:
P=/var/www/html/wp-content/plugins; set -o pipefail; ln -sfn /workspace/checks/C1/mutant $P/optimole-wp && cd /workspace…printedFailed asserting that actual size 2001 matches expected size 1001.(run R4) - Caller and cap analysis is reused from run code-review-agent_6ad7cdfbc64532.06410597 at
f4e1549, not rerun. The new commit leaves that code unchanged.
Untested areas
- Caps and limits: Realistic volume. No data shows how many distinct URLs real pages hold. Issue #1139 says the telemetry lacks it.
- The base-tree run of the changed test failed for a sandbox reason. The base code also lacks the new constant.
- Jest and Playwright suites were not run. The change does not touch them.
🤖 Automated review · run code-review-agent_6ad7d7a5a67722.57858839.
🤖 Review agent — review posted ✅ on cc26c370 · approved · 0 findings · 6 min
Run code-review-agent_6ad7d7a5a67722.57858839 · trail
rodica-andronache
marked this pull request as ready for review
October 22, 2026 05:51
Collaborator
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.
Requested by Marius · project thread
All Submissions:
Changes proposed in this Pull Request:
Part of #1139.
Optml_Attachment_Cache::$cache_mapkeeps every distinct attachment URL looked up during a request, misses included, with no limit. On pages with many offloaded or DAM image URLs it grows for the whole request.The map now holds at most
MAX_MEMORY_ENTRIES(2000) URLs. When it's full, the older half is dropped. Dropped URLs are still served from the persistent cache (transient, or the object cache when one is used), so the only cost is one extra lookup per dropped URL. Updating a URL that's already in the map never triggers a drop.Scope: this bounds the growth path the issue's diagnosis names. The telemetry doesn't say how many URLs those pages had, so I can't prove this map alone is what took the 128 MB. WordPress's own runtime caches of transients and notoptions also grow per URL, and this PR doesn't touch those. If the crash still shows up after this ships, the next place to look is those per-URL transient reads.
How to test the changes in this Pull Request:
memory_get_peak_usage()before and after this change. The in-memory map stays at or below 2000 entries.Other information:
tests/test-attachment-cache.php: map bounded on cache misses, dropped entries still served from the persistent cache, updating a known URL keeps the mapNot proven: that this fixes the production memory fatal (see Scope). Codex review was skipped because the Codex CLI isn't available in this environment.
Generated by Claude Code