Skip to content

[6.x] Speed up permission checks - #15773

Merged
duncanmcclean merged 1 commit into
6.xfrom
cache-permission-values
Nov 2, 2026
Merged

duncanmcclean merged 1 commit into
6.xfrom
cache-permission-values

Conversation

@duncanmcclean

Copy link
Copy Markdown
Member

This pull request speeds up permission checks by caching the values of the flattened permissions.

Statamic's Gate::after callback checks whether an ability is a Statamic permission before getting involved. To do that, it mapped every flattened permission (~475 of them) to its value on every single gate check.

#12258 already caches the flattened permissions, so this PR caches their values in a lookup alongside them, via a new Permissions::contains() method. The values come from the same cached, flattened permissions, so the result of every check is the same as before. It's just quicker to get to.

On an entry where the publish form makes ~2,300 permission checks (mostly from Assets fields), this saved ~190ms.

Related: #12258
Related: #13385

@duncanmcclean
duncanmcclean merged commit d573ee2 into 6.x Nov 2, 2026
65 checks passed
@duncanmcclean
duncanmcclean deleted the cache-permission-values branch November 2, 2026 17:13
joshdaugherty added a commit to UAMS-Web/aether-incomplete-entries that referenced this pull request Nov 10, 2026
Closes #40.

Pins the behavior that `statamic/cms` 6.40.0 changes on code this add-on
calls, so the bump in #24 is judged against tests that fail if that
behavior moves. No `src/` file changes.

## Approach

- **Permission checks (statamic/cms#15773).** A new
`IncompletePublishedEntriesPermissionTest.php` signs in users holding
roles made of single permissions and reads what the widget shows them:
`view` on one collection, `edit` without `view`, and `edit` with and
without `edit other authors`. Roles are saved to a role file of the
test's own, so no other process reads them.
- **Field option defaults (statamic/cms#15772).**
`EntryValidatorTest.php` validates four entries in one process against a
blueprint whose fields differ in `validate`, `if` and `unless`, and
expects each field judged on its own options. A second test runs
`select`, `checkboxes`, `link` and `assets` fields through the
validator, each reporting a missing required value and accepting a
present one. The assets row uses a disk of its own per run, removed
afterwards.
- **Cold Stache (statamic/cms#15771).**
`IncompletePublishedEntriesOffRequestTest.php` scans, clears the Stache,
scans again, and expects an identical result.

## Verification

- With the widget's `can('view', $entry)` replaced by `true`, the three
permission tests fail (3 failed, 8 assertions); restored, they pass.
- The cold-Stache test fails when the failing entry is deleted between
the two scans, and passes unmodified.
- The option and fieldtype tests discriminate through present and
missing values in the same test; no mutation of `src/` was run against
them, since the behavior they pin lives in Statamic.
- `composer ci`: 413 tests passed (1130 assertions), PHPStan clean, Pint
and Rector clean, parallel-safety check OK.

## Test plan

- [x] `composer ci` passes locally on the branch.
- [x] Remote checks pass on this pull request (33 check runs on the head
commit, none failed; the lowest-supported `statamic/cms` job included).
- [x] The tests also pass on the #24 branch: the three changed test
files, installed from its lock (`statamic/cms` v6.40.0), 60 passed.

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
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