diff --git a/src/Stache/Query/Builder.php b/src/Stache/Query/Builder.php index 0f3a7fba9f3..58dfd01bade 100644 --- a/src/Stache/Query/Builder.php +++ b/src/Stache/Query/Builder.php @@ -143,7 +143,7 @@ protected function getCountForPagination() protected function getItems($keys) { - return $this->store->getItems($keys); + return $this->store->getItems($keys)->filter()->values(); } protected function filterWhereBasic($values, $where) diff --git a/tests/Stache/Repositories/EntryRepositoryTest.php b/tests/Stache/Repositories/EntryRepositoryTest.php index 0bdb1cf80fa..e6fb299c134 100644 --- a/tests/Stache/Repositories/EntryRepositoryTest.php +++ b/tests/Stache/Repositories/EntryRepositoryTest.php @@ -71,6 +71,21 @@ public function it_gets_all_entries() ], $entries->map->id()->sort()->values()->all()); } + #[Test] + public function it_ignores_keys_in_indexes_that_no_longer_have_corresponding_files() + { + $store = $this->stache->store('entries')->store('alphabetical'); + + $store->index('title')->load(); + (function () { + $this->paths = $this->paths()->forget('alphabetical-bravo'); + })->call($store); + + $entries = $this->repo->query()->whereIn('title', ['Alpha', 'Bravo', 'Zulu'])->get(); + + $this->assertEquals(['alphabetical-alpha', 'alphabetical-zulu'], $entries->map->id()->all()); + } + #[Test] public function it_gets_entries_from_a_collection() {