1
0

Improved rendering and deploying times

This commit is contained in:
Richard Dern 2024-04-26 23:05:49 +02:00
parent a95c0900e7
commit 7726b3c3e0
7 changed files with 59 additions and 16 deletions

View File

@ -11,6 +11,7 @@
use Exception; use Exception;
use Illuminate\Filesystem\FilesystemAdapter; use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use League\Flysystem\StorageAttributes; use League\Flysystem\StorageAttributes;
@ -176,9 +177,14 @@ public function load(): void
*/ */
public function save(): void public function save(): void
{ {
$this->saveAttachments(); if (
$this->saveMetadata(); $this->saveAttachments()
$this->saveMarkdown(); || $this->saveMetadata()
|| $this->saveMarkdown()
) {
$this->metadata()->set('lastModified', now()->toIso8601String());
$this->saveMetadata();
}
} }
/** /**
@ -195,9 +201,23 @@ public function repair(): void
public function render() 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() public function renderCard()

View File

@ -54,11 +54,17 @@ private function loadAttachments()
/** /**
* Save all attachments files that needs to be * Save all attachments files that needs to be
*/ */
private function saveAttachments() private function saveAttachments(): bool
{ {
$allSaved = true;
foreach ($this->attachmentsManagers as $manager) { foreach ($this->attachmentsManagers as $manager) {
$manager->save(); if (!$manager->save()) {
$allSaved = false;
}
} }
return $allSaved;
} }
/** /**

View File

@ -45,9 +45,15 @@ private function loadMarkdown()
*/ */
private function saveMarkdown() private function saveMarkdown()
{ {
$allSaved = true;
foreach ($this->markdownManagers as $manager) { foreach ($this->markdownManagers as $manager) {
$manager->save(); if (!$manager->save()) {
$allSaved = false;
}
} }
return $allSaved;
} }
/** /**

View File

@ -43,10 +43,16 @@ private function loadMetadata()
/** /**
* Save all metadata files that needs to be * Save all metadata files that needs to be
*/ */
private function saveMetadata() private function saveMetadata(): bool
{ {
$allSaved = true;
foreach ($this->metadataManagers as $manager) { foreach ($this->metadataManagers as $manager) {
$manager->save(); if (!$manager->save()) {
$allSaved = false;
}
} }
return $allSaved;
} }
} }

View File

@ -14,7 +14,7 @@ class Repair extends Command
* *
* @var string * @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. * The console command description.
@ -28,9 +28,14 @@ class Repair extends Command
*/ */
public function handle() public function handle()
{ {
$disk = Storage::disk(env('CONTENT_DISK')); $disk = Storage::disk(env('CONTENT_DISK'));
$path = $this->argument('path') ?? '/'; $path = $this->argument('path') ?? '/';
$bundles = Bundle::findBundles($disk, $path, true);
if ($this->option('recursive')) {
$bundles = Bundle::findBundles($disk, $path, true);
} else {
$bundles = [new Bundle($path, $disk)];
}
foreach ($bundles as $bundle) { foreach ($bundles as $bundle) {
$this->output->write(sprintf('Repairing %s... ', $bundle->getPath())); $this->output->write(sprintf('Repairing %s... ', $bundle->getPath()));

View File

@ -20,7 +20,7 @@ public function render()
data_set($this->viewData, 'showToc', true); data_set($this->viewData, 'showToc', true);
data_set($this->viewData, 'dossier', $dossier); data_set($this->viewData, 'dossier', $dossier);
return [$this->bundle->getPath() => view('article', $this->viewData)]; return [$this->bundle->getPath() => (string) view('article', $this->viewData)];
} }
/** /**

View File

@ -27,7 +27,7 @@ public function render()
data_set($this->viewData, 'relations', $relations); data_set($this->viewData, 'relations', $relations);
return [$this->bundle->getPath() => view('term', $this->viewData)]; return [$this->bundle->getPath() => (string) view('term', $this->viewData)];
} }
/** /**