Repository navigation
[6.x] Speed up Stache entry file filtering on multisite - #15825
Conversation
With multisite enabled, CollectionEntriesStore::getItemFilter() looked up the collection (from the cache store) for every file. Resolve the store directory and the collection's sites once per traversal instead, via a new protected Store::traverseFiles() method. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-filter # Conflicts: # src/Stache/Stores/CollectionEntriesStore.php # tests/Stache/Stores/EntriesStoreTest.php
…eparate traversal hook Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Thanks Ryan I pushed a small tweak that avoids that repeated lookup by reusing $collection = $this->collection ?? $this->findCollection($this->childKey);
if (! $collection->sites()->contains($site)) {
return false;
}I swapped the test for one that checks the collection is only looked up once while filtering on multisite. Benchmarks (10,002 files over 3 sites, collection on 2 of them, real file cache):
Cache reads of the collection go from 10,002 down to 1. Your original version was ~40ms faster on raw traversal, but that's within noise once entries are built, so I went with the simpler approach. |
|
Awesome. Thanks. |
When multisite is enabled,
CollectionEntriesStore::getItemFilter()called$this->collection()->sites()for every file it filtered. That goes throughCollection::findByHandle(), which fetches the collection from the Stache cache store each time. The filter runs whenever a store's files are listed: on a cold build, and on every request while the watcher is enabled.This PR resolves the store directory and the collection's sites once per traversal and has the filter read those values.
Store::traverseFiles()method wraps the existingTraverser::filter([$this, 'getItemFilter'])->traverse($this)call. Both places that list files now use it.CollectionEntriesStoreoverrides it to resolve the directory and sites before traversing, and clears them afterwards.getItemFilter()still works on its own. When called directly, outside a traversal, it falls back to the previous per-file lookup.Benchmark
10,000 entry files in a two-site collection, using the in-memory test cache. With the default file cache, each lookup also reads from disk, so the saving should be larger.
Single-site installs only save a little, since they never did the collection lookup.
Tests
I added a test that checks a multisite collection only gets files from its own sites, both through
getItemFilter()directly and throughtraverseFiles().🤖 Generated with Claude Code