forked from Alex/Pterodactyl-Panel
Don't cache the manifest like this, pointless
This commit is contained in:
parent
293ebc9344
commit
edf27a5542
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user