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 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();
if (
$this->saveAttachments()
|| $this->saveMetadata()
|| $this->saveMarkdown()
) {
$this->metadata()->set('lastModified', now()->toIso8601String());
$this->saveMetadata();
$this->saveMarkdown();
}
}
/**
@ -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()

View File

@ -54,13 +54,19 @@ 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;
}
/**
* Repair all attachments files that needs to be
*/

View File

@ -45,11 +45,17 @@ private function loadMarkdown()
*/
private function saveMarkdown()
{
$allSaved = true;
foreach ($this->markdownManagers as $manager) {
$manager->save();
if (!$manager->save()) {
$allSaved = false;
}
}
return $allSaved;
}
/**
* Lint all markdowns in the bundle
*/

View File

@ -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;
}
}

View File

@ -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.
@ -30,7 +30,12 @@ public function handle()
{
$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()));

View File

@ -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)];
}
/**

View File

@ -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)];
}
/**