Repository navigation
fix(databases): refresh cached lists when document permissions change - #14869
Conversation
On collections with document security, writes that set document permissions now purge the collection's cached lists: single update and upsert, bulk update and upsert carrying $permissions, and committed transaction operations. A cache failure during transaction commit is logged rather than failing the commit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review complete. No blocking issues — approved ✅; 2 nitpicks below. 🧹 Nitpicks (2) — 🟢 2 low
This PR introduces permission-change-aware list-cache invalidation for DocumentsDB: when a caller supplies $permissions on document writes, the collection's cached list responses are purged so revoked callers stop seeing stale rows. The purge is wired through the shared Databases/Action helper plus the single update/upsert, bulk update/upsert, and transaction commit paths, and is covered by a new e2e test asserting cache bust on permission revocation.
Reviewed commit: e5684f3 |
🟢 Tier S · Ready to mergeThis pull request invalidates cached document-list responses when document permissions change through single or bulk writes and committed transactions. List requests capture a cache version before querying and save their results only if that version is still current; version markers now also expire. E2E and unit tests cover invalidation, races, cache failures, and marker expiration. Latest changes: The newest commit gives each list-cache version marker a 24-hour TTL and adds a unit test that verifies Redis expires the marker.
📂 Walkthrough · 11
Merged |
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
…purging after Purging the cached lists after a permission write committed had two failure modes. Where the purge was uncaught, a cache outage returned an error for a write that was already stored and skipped its events. Where it was caught, the stale entries survived and were served again once the cache recovered. A write that sets document permissions on a collection with document security now runs behind a fence on that collection's list cache: - Before the write, it registers a token in a sibling hash and then purges the list hash, which also advances the hash's generation. If either step fails, the write is refused before anything is stored. - While any token is live, lists are still read but nothing is saved. - A list saves its result with saveWithLease under the generation it read before checking the fences, so a read that raced the purge is dropped rather than cached. - After the write, the token is released. A failed release is logged and never fails the stored write. Its token lapses after 300 seconds, during which lists are served uncached. No cache failure can leave a pre-write list servable: the purge either happened before the write or the write never ran. The one assumption is that no write runs longer than the fence lapse. Single and bulk update and upsert, and transaction commits, all fence the same way. A commit fences every collection one of its operations sets permissions in before the database transaction starts. The e2e test now also covers single upsert, bulk upsert and a transaction that commits a bulk upsert. ListCacheTest covers the fence against a Redis cache that goes down mid-write. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ons' into fix/list-cache-document-permissions
…ache A fence that cannot be registered refuses the write before it is stored. Raise it as Utopia\Cache\Exception\Unavailable so the error hook answers 503 general_cache_unavailable, which clients may retry, instead of a 500. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The findings that requested changes are resolved. See the summary comment for what is still open.
Replace the fence, lease and generation machinery with two purges around the write, which is simpler and adds no Redis calls to the list read path. - Before a write that sets document permissions on a collection with document security, its cached lists are purged. If the purge fails, the write is refused before anything is stored, with 503 general_cache_unavailable. A cache outage therefore cannot leave a list cached before the write. - After the write, the lists are purged again, best-effort. A failure is logged, and the stored write still succeeds and runs its events. This purge also clears a list a concurrent reader cached between the first purge and the commit. - A transaction commit purges every affected collection before the database transaction starts. If that fails, the commit fails like any other commit error. Accepted residual window: a list cached between the first purge and the commit survives only if the second purge also fails, and then lives until its TTL. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…took Purging before and after a permission write does not stop a list request that missed the cache before or during the write from saving its pre-write rows after the last purge. The revoked rows would then be served until the entry's TTL. Every list cache purge now also writes a new version to a sibling key. On a cache miss, a list request reads the version before it queries. After the query, it saves the result only if the version is unchanged. Otherwise it returns the rows without caching them. If the version cannot be read, the request is served uncached. Cache hits make no extra calls. Accepted leftover: a purge that lands between the version re-check and the save is not seen, so that save can still survive. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The findings that requested changes are resolved. See the summary comment for what is still open.
What does this PR do?
On collections with document security, writes that set document permissions now purge the collection's cached lists: single update and upsert, bulk update and upsert carrying $permissions, and committed transaction operations. A cache failure during transaction commit is logged rather than failing the commit.
Test Plan
New e2e testListDocumentsCacheBustedByDocumentPermissionChange covering single update, bulk update and a committed transaction, plus the existing cache, bulk, upsert, permission and transaction suites on Legacy and TablesDB. Lint and PHPStan are clean.
Related PRs and Issues
Checklist
🤖 Generated with Claude Code