Stache index built on first use leaves a stale file collection that the next `warm()` indexes from

Đang mở
#16,022 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@joshdaugherty đang làm issue này rồi.

Từ ngày 24/11/2026.

  • #16024 của @joshdaugherty — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
Nửa ngày
Mức phù hợp với người mới
58/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
php, rails
Lĩnh vực
backend

Hướng nghiên cứu

Start in Store.php, where getItemsFromFiles() assigns $this->fileItems and warm() sets $shouldCacheFileItems before building indexes. Check the reset behaviour in clear() and in the store reset used between jobs and Octane requests, and confirm ContainerAssetsStore reads $fileItems the same way. Reproduce with the steps in the issue in a test under tests/Stache. Done when a term file written after an empty query is indexed by a later warm(), and the existing tests/Stache suite still passes.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

stache
Bug description

Store::getItemsFromFiles() assigns $this->fileItems on every call, including outside a warm. warm() sets $shouldCacheFileItems and then reuses that collection for every index it updates, nulling it only after the indexes are built. Nothing else resets it: clear() does not, and neither does the store reset that runs between queue jobs and between Octane requests (Statamic\Stache\ServiceProvider::resetMemoizedStateBetweenJobs() and resetMemoizedStateBetweenOctaneRequests()), which clears each store's paths and indexes.

When an index is built on first use while a taxonomy is empty, the empty collection stays in $fileItems. A later warm() builds every index from that collection, so a term file written in between is missing from the title index and Term::whereTaxonomy() does not return it. Since #15897 (v6.43.0) clear() keeps the record of used indexes, so a clear() followed by warm() also builds the title index, and builds it from the stale collection. On v6.42.0 the same sequence returns the term.

Expected: a warm() indexes the files on disk when it runs.

Store.php is byte-identical on v6.43.0, v6.43.1, v6.43.2 and 6.x.

How to reproduce

On v6.43.1, in a test that extends Tests\TestCase and uses PreventSavingStacheItemsToDisk, with an empty tags taxonomy whose terms directory is a temporary directory:

  1. Read Stache::store('terms')->store('tags')->index('title')->keys(). It is empty, and the store now holds an empty $fileItems.
  2. Write tags/default_news.yaml containing title: Default News.
  3. Run Stache::stores()->each->resetMemoizedState() and app('stache.indexes')->each->resetMemoizedState(), which is what the service provider does between jobs.
  4. Call warm() on the tags store, reset the memoized state again, and read the title index keys.

Result: 0 keys. Expected: 1. The same file written after an empty query also goes unindexed after clear() then warm(), and after Stache::refresh().

Proposed fix, which makes all three cases return 1 and leaves tests/Stache passing (256 passed, 12 incomplete, 0 failed):

     public function warm()
     {
+        $this->fileItems = null;
+
         $this->shouldCacheFileItems = true;

warm() is the only reader of $fileItems, because getItemsFromFiles() in Store and in ContainerAssetsStore read it only while $shouldCacheFileItems is true. A reset in clear() alone does not cover the worker case. Assigning $fileItems only while caching would be an alternative, and it has not been tested.

Logs
None. No error is raised; the index is silently empty.
Environment
Not applicable: reproduced in a test suite, not on a site.
statamic/cms: v6.43.1 (71387ae6a13659529b135d87b0c5b8eafe2ca7c0)
OS: Windows 11
PHP: 8.4.27
Installation

Other (please explain)

Additional details

Reproduced in a statamic/cms checkout, with a downstream host app on Laravel. The sequence in step 3 is simulated with the provider's own reset calls. A live queue worker or Octane process was not run.

No existing report found on statamic/cms (searched issues and pull requests, open and closed). The open pull request #15856 changes getItemsFromFiles() for an opt-in index build and does not address this.

Ngôn ngữ chính
PHP
Star
4.9k
Fork
647
Merge trung bình
1 ngày 45 phút
Pull request đã merge (30 ngày)
221

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của statamic/cms

Tất cả issue của statamic/cms

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.