Skip to content

Cache empty getDocument results#924

Open
fogelito wants to merge 3 commits into
mainfrom
cache-empty-get-document
Open

Cache empty getDocument results#924
fogelito wants to merge 3 commits into
mainfrom
cache-empty-get-document

Conversation

@fogelito

@fogelito fogelito commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Performance

    • Improved handling of repeated lookups for missing documents and collections via negative caching.
    • Added select/projection-aware caching for missing-document markers, reducing unnecessary cache churn.
  • Bug Fixes

    • Newly created documents and collections now immediately replace prior “not found” cache markers.
    • Locking/for-update reads no longer populate negative cache entries.
    • Permission-denied reads no longer poison shared negative-cache results across different access contexts.
  • Tests

    • Added end-to-end coverage for missing-document and missing-collection caching, invalidation on create (single and batch), projection behavior, and security.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@fogelito, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 11 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 587862c9-ff97-4f30-865c-fa00b5880425

📥 Commits

Reviewing files that changed from the base of the PR and between 0085de2 and b1203dd.

📒 Files selected for processing (1)
  • src/Database/Database.php
📝 Walkthrough

Walkthrough

Database now negative-caches eligible document and collection misses with an empty marker. Document creation purges matching markers using tenant-aware keys, adapter capabilities identify cache-layer support, and end-to-end tests cover projections, batch creation, locking reads, collection metadata, and security behavior.

Changes

Negative cache lifecycle

Layer / File(s) Summary
Adapter cache capability contract
src/Database/Adapter.php, src/Database/Adapter/{Memory,Mongo,Pool,Redis,SQL}.php
Adapters expose cache-layer support, with pooled delegation and adapter-specific capability values.
Negative-cache read and write path
src/Database/Database.php
getDocument() recognizes cached empty markers and stores markers for eligible missing-document reads.
Creation-time cache invalidation
src/Database/Database.php
Single and batch document creation purge tenant-aware negative-cache entries through a shared helper.
Negative-cache behavior coverage
tests/e2e/Adapter/Scopes/DocumentTests.php
End-to-end tests cover document and collection misses, projections, creation invalidation, locking reads, and document-level security.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Database
  participant Cache
  Client->>Database: Read missing document
  Database->>Cache: Save empty marker
  Cache-->>Database: Empty marker stored
  Client->>Database: Create document
  Database->>Cache: Purge document marker
  Cache-->>Database: Marker invalidated
  Client->>Database: Read created document
  Database-->>Client: Return document
Loading

Possibly related PRs

Suggested reviewers: abnegate

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: caching empty getDocument results via negative caching.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cache-empty-get-document

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds negative caching for missing documents and collections. The main changes are:

  • Cache markers for missing document lookups.
  • Marker invalidation after single and batch creation.
  • Protection for locking reads and permission-filtered results.
  • Projection-aware cache entries and tenant-aware purging.
  • Adapter capability reporting and expanded end-to-end tests.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
src/Database/Database.php Adds negative-cache reads, writes, and tenant-aware invalidation after document creation.
src/Database/Adapter.php Adds the adapter cache-capability contract.
src/Database/Adapter/Memory.php Reports support for the Database cache layer.
src/Database/Adapter/Mongo.php Reports support for the Database cache layer.
src/Database/Adapter/Pool.php Delegates cache-capability reporting to the pooled adapter.
src/Database/Adapter/Redis.php Reports that Redis bypasses the separate Database cache layer.
src/Database/Adapter/SQL.php Reports cache support for SQL-based adapters.
tests/e2e/Adapter/Scopes/DocumentTests.php Covers missing-result caching, invalidation, projections, locking reads, collections, and document security.
composer.lock Refreshes locked dependency versions.

Reviews (3): Last reviewed commit: "withDocumentTenant" | Re-trigger Greptile

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/Database/Database.php`:
- Around line 8460-8483: Update purgeCreatedDocumentCache() to wrap both the
tenant-scoped withTenant() path and direct purgeCachedDocumentInternal() call in
exception handling, logging cache purge failures with Console::warning while
allowing the committed createDocument/createDocuments operation to succeed. Keep
the existing tenant resolution and purge behavior unchanged; do not refactor the
duplicated tenant wrapper.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 231a6f04-a567-4008-9e9e-2e0a5df8d4b9

📥 Commits

Reviewing files that changed from the base of the PR and between a1796fd and 538e228.

⛔ Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • src/Database/Database.php
  • tests/e2e/Adapter/Scopes/DocumentTests.php

Comment thread src/Database/Database.php

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/Database/Adapter.php`:
- Around line 1125-1132: Make getSupportForCaching() in Adapter non-abstract and
provide the default caching behavior, then explicitly override it in built-in
adapters where their cache support differs. Preserve existing downstream adapter
instantiation without requiring new method implementations.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 188d43d8-2323-4f76-a6a7-13476a829e47

📥 Commits

Reviewing files that changed from the base of the PR and between 538e228 and 0085de2.

📒 Files selected for processing (7)
  • src/Database/Adapter.php
  • src/Database/Adapter/Memory.php
  • src/Database/Adapter/Mongo.php
  • src/Database/Adapter/Pool.php
  • src/Database/Adapter/Redis.php
  • src/Database/Adapter/SQL.php
  • tests/e2e/Adapter/Scopes/DocumentTests.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/e2e/Adapter/Scopes/DocumentTests.php

Comment thread src/Database/Adapter.php
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.

1 participant