From edf27a55421514f3166d354d03041b2910e661f6 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 22 Dec 2019 15:41:38 -0800 Subject: [PATCH] Don't cache the manifest like this, pointless --- app/Services/Helpers/AssetHashService.php | 37 +++++------------------ 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/app/Services/Helpers/AssetHashService.php b/app/Services/Helpers/AssetHashService.php index c02506a9..c3d4c98f 100644 --- a/app/Services/Helpers/AssetHashService.php +++ b/app/Services/Helpers/AssetHashService.php @@ -2,10 +2,9 @@ namespace Pterodactyl\Services\Helpers; -use Cake\Chronos\Chronos; +use Illuminate\Support\Arr; use Illuminate\Filesystem\FilesystemManager; use Illuminate\Contracts\Foundation\Application; -use Illuminate\Contracts\Cache\Repository as CacheRepository; class AssetHashService { @@ -14,11 +13,6 @@ class AssetHashService */ public const MANIFEST_PATH = './assets/manifest.json'; - /** - * @var \Illuminate\Contracts\Cache\Repository - */ - private $cache; - /** * @var \Illuminate\Contracts\Filesystem\Filesystem */ @@ -38,13 +32,11 @@ class AssetHashService * AssetHashService constructor. * * @param \Illuminate\Contracts\Foundation\Application $application - * @param \Illuminate\Contracts\Cache\Repository $cache * @param \Illuminate\Filesystem\FilesystemManager $filesystem */ - public function __construct(Application $application, CacheRepository $cache, FilesystemManager $filesystem) + public function __construct(Application $application, FilesystemManager $filesystem) { $this->application = $application; - $this->cache = $cache; $this->filesystem = $filesystem->createLocalDriver(['root' => public_path()]); } @@ -59,9 +51,9 @@ class AssetHashService public function url(string $resource): string { $file = last(explode('/', $resource)); - $data = array_get($this->manifest(), $file, $file); + $data = Arr::get($this->manifest(), $file) ?? $file; - return str_replace($file, array_get($data, 'src', $file), $resource); + return str_replace($file, Arr::get($data, 'src') ?? $file, $resource); } /** @@ -77,7 +69,7 @@ class AssetHashService $file = last(explode('/', $resource)); $data = array_get($this->manifest(), $file, $file); - return array_get($data, 'integrity', ''); + return Arr::get($data, 'integrity') ?? ''; } /** @@ -122,21 +114,8 @@ class AssetHashService */ protected function manifest(): array { - if (! is_null(self::$manifest)) { - return self::$manifest; - } - - // Skip checking the cache if we are not in production. - if ($this->application->environment() === 'production') { - $stored = $this->cache->get('Core:AssetManifest'); - if (! is_null($stored)) { - return self::$manifest = $stored; - } - } - - $contents = json_decode($this->filesystem->get(self::MANIFEST_PATH), true); - $this->cache->put('Core:AssetManifest', $contents, Chronos::now()->addMinutes(1440)); - - return self::$manifest = $contents; + return self::$manifest ?: self::$manifest = json_decode( + $this->filesystem->get(self::MANIFEST_PATH), true + ); } }