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

[5.x] Add ability to specify which Stache stores to warm #9694

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 6 additions & 2 deletions src/Console/Commands/StacheWarm.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class StacheWarm extends Command
{
use RunsInPlease;

protected $signature = 'statamic:stache:warm';
protected $signature = 'statamic:stache:warm {store?}';
protected $description = 'Build the "Stache" cache';

public function handle()
Expand All @@ -20,7 +20,11 @@ public function handle()

$this->line('Please wait. This may take a while if you have a lot of content.');

Stache::warm();
if ($stores = $this->argument('store')) {
$stores = collect(explode(',', $stores))->map(fn ($store) => trim($store))->all();
}

Stache::warm($stores ?? []);

$this->info('You have poured oil over the Stache and polished it until it shines. It is warm and ready');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Facades/Stache.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @method static string generateId()
* @method static self clear()
* @method static void refresh()
* @method static void warm()
* @method static void warm($stores = [])
* @method static self instance()
* @method static mixed fileCount()
* @method static mixed|null fileSize()
Expand Down
10 changes: 8 additions & 2 deletions src/Stache/Stache.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,21 @@ public function refresh()
return $this->clear()->warm();
}

public function warm()
public function warm($stores = [])
{
Partyline::comment('Warming Stache...');

$lock = tap($this->lock('stache-warming'))->acquire(true);

$this->startTimer();

$this->stores()->each->warm();
$this->stores()->where(function ($store, $key) use ($stores) {
if (count($stores) == 0) {
return true;
}

return in_array($key, $stores);
})->each->warm();

$this->stopTimer();

Expand Down
Loading