-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b83178
commit fddccc7
Showing
4 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Spatie\Sheets\Console; | ||
|
||
use Spatie\Sheets\Sheets; | ||
use Illuminate\Console\Command; | ||
|
||
class WarmCommand extends Command | ||
{ | ||
protected $signature = 'sheets:warm {--collection=}'; | ||
|
||
protected $description = 'Warm up the caches for Sheets collections'; | ||
|
||
/** @var \Spatie\Sheets\Sheets */ | ||
protected $sheets; | ||
|
||
public function __construct(Sheets $sheets) | ||
{ | ||
parent::__construct(); | ||
|
||
$this->sheets = $sheets; | ||
} | ||
|
||
public function handle() | ||
{ | ||
if ($this->option('collection')) { | ||
$this->warm($this->option('collection')); | ||
|
||
return; | ||
} | ||
|
||
$this->sheets->getRegisteredCollectionNames()->each(function (string $collectionName) { | ||
$this->warm($collectionName); | ||
}); | ||
} | ||
|
||
protected function warm(string $collectionName) | ||
{ | ||
$this->sheets->collection($collectionName)->all()->each(function ($sheet) use ($collectionName) { | ||
$this->sheets->collection($collectionName)->get($sheet->slug); | ||
}); | ||
|
||
$this->info("Warmed up {$this->option('collection')}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Spatie\Sheets\Tests\Integration\Console; | ||
|
||
use Spatie\Sheets\Sheets; | ||
use Spatie\Sheets\Tests\Integration\TestCase; | ||
use Illuminate\Support\Facades\Artisan; | ||
|
||
class WarmCommandTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_warms_up_all_caches() | ||
{ | ||
$this->assertFalse($this->app->cache->has('sheets:content-1:__all')); | ||
$this->assertFalse($this->app->cache->has('sheets:content-1:hello-world')); | ||
$this->assertFalse($this->app->cache->has('sheets:content-2:__all')); | ||
$this->assertFalse($this->app->cache->has('sheets:content-2:hello-world')); | ||
|
||
Artisan::call('sheets:warm'); | ||
|
||
$this->assertTrue($this->app->cache->has('sheets:content-1:__all')); | ||
$this->assertTrue($this->app->cache->has('sheets:content-1:hello-world')); | ||
$this->assertTrue($this->app->cache->has('sheets:content-2:__all')); | ||
$this->assertTrue($this->app->cache->has('sheets:content-2:hello-world')); | ||
} | ||
|
||
protected function getEnvironmentSetUp($app) | ||
{ | ||
$app['config']->set('filesystems.disks.content-1', [ | ||
'driver' => 'local', | ||
'root' => __DIR__.'/../../fixtures/content', | ||
]); | ||
|
||
$app['config']->set('filesystems.disks.content-2', [ | ||
'driver' => 'local', | ||
'root' => __DIR__.'/../../fixtures/content', | ||
]); | ||
|
||
$app['config']->set('sheets', [ | ||
'collections' => ['content-1', 'content-2'], | ||
]); | ||
} | ||
} |