Improved rendering and deploying times
This commit is contained in:
parent
a95c0900e7
commit
7726b3c3e0
|
@ -11,6 +11,7 @@
|
|||
use Exception;
|
||||
use Illuminate\Filesystem\FilesystemAdapter;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Str;
|
||||
use League\Flysystem\StorageAttributes;
|
||||
|
||||
|
@ -176,9 +177,14 @@ public function load(): void
|
|||
*/
|
||||
public function save(): void
|
||||
{
|
||||
$this->saveAttachments();
|
||||
$this->saveMetadata();
|
||||
$this->saveMarkdown();
|
||||
if (
|
||||
$this->saveAttachments()
|
||||
|| $this->saveMetadata()
|
||||
|| $this->saveMarkdown()
|
||||
) {
|
||||
$this->metadata()->set('lastModified', now()->toIso8601String());
|
||||
$this->saveMetadata();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -195,9 +201,23 @@ public function repair(): void
|
|||
|
||||
public function render()
|
||||
{
|
||||
$renderer = BundleRenderer::getBundleRendererFor($this);
|
||||
$lastModified = Carbon::parse($this->metadata()->get('lastModified', '1970-01-02'));
|
||||
$lastRendered = Carbon::parse($this->metadata()->get('lastRendered', '1970-01-01'));
|
||||
$cacheKey = sprintf('render_%s', Str::slug($this->getPath()));
|
||||
|
||||
return $renderer->render();
|
||||
if ($lastRendered->gt($lastModified) && Cache::has($cacheKey)) {
|
||||
return Cache::get($cacheKey);
|
||||
}
|
||||
|
||||
$renderer = BundleRenderer::getBundleRendererFor($this);
|
||||
$result = $renderer->render();
|
||||
|
||||
$this->metadata()->set('lastRendered', now()->toIso8601String());
|
||||
$this->metadata()->save();
|
||||
|
||||
Cache::put($cacheKey, $result, now()->addMonth());
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function renderCard()
|
||||
|
|
|
@ -54,11 +54,17 @@ private function loadAttachments()
|
|||
/**
|
||||
* Save all attachments files that needs to be
|
||||
*/
|
||||
private function saveAttachments()
|
||||
private function saveAttachments(): bool
|
||||
{
|
||||
$allSaved = true;
|
||||
|
||||
foreach ($this->attachmentsManagers as $manager) {
|
||||
$manager->save();
|
||||
if (!$manager->save()) {
|
||||
$allSaved = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $allSaved;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -45,9 +45,15 @@ private function loadMarkdown()
|
|||
*/
|
||||
private function saveMarkdown()
|
||||
{
|
||||
$allSaved = true;
|
||||
|
||||
foreach ($this->markdownManagers as $manager) {
|
||||
$manager->save();
|
||||
if (!$manager->save()) {
|
||||
$allSaved = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $allSaved;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -43,10 +43,16 @@ private function loadMetadata()
|
|||
/**
|
||||
* Save all metadata files that needs to be
|
||||
*/
|
||||
private function saveMetadata()
|
||||
private function saveMetadata(): bool
|
||||
{
|
||||
$allSaved = true;
|
||||
|
||||
foreach ($this->metadataManagers as $manager) {
|
||||
$manager->save();
|
||||
if (!$manager->save()) {
|
||||
$allSaved = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $allSaved;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ class Repair extends Command
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'bundle:repair { path? : Specific bundle to repair }';
|
||||
protected $signature = 'bundle:repair { --r|recursive : Also repair sub-bundles } { path? : Specific bundle to repair }';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
|
@ -28,9 +28,14 @@ class Repair extends Command
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
$disk = Storage::disk(env('CONTENT_DISK'));
|
||||
$path = $this->argument('path') ?? '/';
|
||||
$bundles = Bundle::findBundles($disk, $path, true);
|
||||
$disk = Storage::disk(env('CONTENT_DISK'));
|
||||
$path = $this->argument('path') ?? '/';
|
||||
|
||||
if ($this->option('recursive')) {
|
||||
$bundles = Bundle::findBundles($disk, $path, true);
|
||||
} else {
|
||||
$bundles = [new Bundle($path, $disk)];
|
||||
}
|
||||
|
||||
foreach ($bundles as $bundle) {
|
||||
$this->output->write(sprintf('Repairing %s... ', $bundle->getPath()));
|
||||
|
|
|
@ -20,7 +20,7 @@ public function render()
|
|||
data_set($this->viewData, 'showToc', true);
|
||||
data_set($this->viewData, 'dossier', $dossier);
|
||||
|
||||
return [$this->bundle->getPath() => view('article', $this->viewData)];
|
||||
return [$this->bundle->getPath() => (string) view('article', $this->viewData)];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,7 +27,7 @@ public function render()
|
|||
|
||||
data_set($this->viewData, 'relations', $relations);
|
||||
|
||||
return [$this->bundle->getPath() => view('term', $this->viewData)];
|
||||
return [$this->bundle->getPath() => (string) view('term', $this->viewData)];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user