Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent handling collection changes on every request #2572

Merged
merged 2 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Stache/Stores/CollectionsStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ public function handleFileChanges()

parent::handleFileChanges();

// TODO: only update urls for structured collection that were modified.
Collection::all()->each->updateEntryUris();
foreach ($this->modified as $collection) {
$collection->updateEntryUris();

// TODO: only update order indexes for collections that were modified.
Collection::all()->filter->orderable()->each(function ($collection) {
Stache::store('entries')->store($collection->handle())->index('order')->update();
});
if ($collection->orderable()) {
Stache::store('entries')->store($collection->handle())->index('order')->update();
}
}
}
}
5 changes: 5 additions & 0 deletions src/Stache/Stores/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ abstract class Store
protected $paths;
protected $fileItems;
protected $shouldCacheFileItems = false;
protected $modified;

public function directory($directory = null)
{
Expand Down Expand Up @@ -156,6 +157,8 @@ protected function storeIndexes()

public function handleFileChanges()
{
$this->modified = collect();

// We only want to act on any file changes one time per store.
if ($this->fileChangesHandled) {
return;
Expand Down Expand Up @@ -268,6 +271,8 @@ public function handleFileChanges()
$index->updateItem($item);
});
});

$this->modified = $modified;
}

protected function handleModifiedItem($item)
Expand Down