1
0

Removed anything related to cache - Permit to sort bundles

This commit is contained in:
Richard Dern 2024-05-09 01:10:24 +02:00
parent 5cf1ae7910
commit beb701d752

View File

@ -11,7 +11,6 @@
use Exception;
use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;
use League\Flysystem\StorageAttributes;
@ -219,24 +218,14 @@ public function touch()
}
}
public function render(bool $ignoreCache = false)
public function render()
{
$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()));
if ($lastRendered->gt($lastModified) && Cache::has($cacheKey) && !$ignoreCache) {
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;
}
@ -250,7 +239,7 @@ public function renderCard()
/**
* Return a list of bundles in the specified path
*/
public static function findBundles(FilesystemAdapter $disk, ?string $path = '/', bool $recursive = false): array
public static function findBundles(FilesystemAdapter $disk, ?string $path = '/', bool $recursive = false, bool $sortByDate = true): array
{
$bundles = [];
@ -272,6 +261,7 @@ public static function findBundles(FilesystemAdapter $disk, ?string $path = '/',
}
}
if ($sortByDate) {
$bundles = collect($bundles)
->sortBy([
fn (Bundle $a, Bundle $b) => Carbon::parse($a->metadata()->get('date'))
@ -280,6 +270,7 @@ public static function findBundles(FilesystemAdapter $disk, ?string $path = '/',
->gt(Carbon::parse($a->metadata()->get('date'))),
])
->toArray();
}
return $bundles;
}