Skip to content

[6.x] Avoid parsing every file when clearing a cold Stache - #15771

Merged
duncanmcclean merged 1 commit into
6.xfrom
faster-stache-clear
Nov 3, 2026
Merged

duncanmcclean merged 1 commit into
6.xfrom
faster-stache-clear

Conversation

@duncanmcclean

Copy link
Copy Markdown
Member

This pull request fixes an issue where clearing the Stache (eg. php please stache:clear or stache:refresh) was slow when the Stache wasn't already warm.

This was happening because Store::clear() called paths() to work out which cached items to forget. When the paths weren't cached, paths() would rebuild them, reading & parsing every file (or listing every file in an asset container) and caching every item... only for clear() to throw it all away. stache:refresh on a cold Stache ended up parsing everything twice.

This PR fixes it by only forgetting items for paths that are actually cached. When the paths aren't cached, any leftover items get overwritten the next time the paths are built, so there's nothing to forget.

With 5,000 entries, clearing a cold Stache went from ~1.8s to ~0.2s.

Fixes #10295

@duncanmcclean
duncanmcclean merged commit e4fc695 into 6.x Nov 3, 2026
65 checks passed
@duncanmcclean
duncanmcclean deleted the faster-stache-clear branch November 3, 2026 10:03
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.

Stache Clear Slow

1 participant