Skip to content

Commit edf27a5

Browse files
committed
Don't cache the manifest like this, pointless
1 parent 293ebc9 commit edf27a5

File tree

1 file changed

+8
-29
lines changed

1 file changed

+8
-29
lines changed

app/Services/Helpers/AssetHashService.php

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
namespace Pterodactyl\Services\Helpers;
44

5-
use Cake\Chronos\Chronos;
5+
use Illuminate\Support\Arr;
66
use Illuminate\Filesystem\FilesystemManager;
77
use Illuminate\Contracts\Foundation\Application;
8-
use Illuminate\Contracts\Cache\Repository as CacheRepository;
98

109
class AssetHashService
1110
{
@@ -14,11 +13,6 @@ class AssetHashService
1413
*/
1514
public const MANIFEST_PATH = './assets/manifest.json';
1615

17-
/**
18-
* @var \Illuminate\Contracts\Cache\Repository
19-
*/
20-
private $cache;
21-
2216
/**
2317
* @var \Illuminate\Contracts\Filesystem\Filesystem
2418
*/
@@ -38,13 +32,11 @@ class AssetHashService
3832
* AssetHashService constructor.
3933
*
4034
* @param \Illuminate\Contracts\Foundation\Application $application
41-
* @param \Illuminate\Contracts\Cache\Repository $cache
4235
* @param \Illuminate\Filesystem\FilesystemManager $filesystem
4336
*/
44-
public function __construct(Application $application, CacheRepository $cache, FilesystemManager $filesystem)
37+
public function __construct(Application $application, FilesystemManager $filesystem)
4538
{
4639
$this->application = $application;
47-
$this->cache = $cache;
4840
$this->filesystem = $filesystem->createLocalDriver(['root' => public_path()]);
4941
}
5042

@@ -59,9 +51,9 @@ public function __construct(Application $application, CacheRepository $cache, Fi
5951
public function url(string $resource): string
6052
{
6153
$file = last(explode('/', $resource));
62-
$data = array_get($this->manifest(), $file, $file);
54+
$data = Arr::get($this->manifest(), $file) ?? $file;
6355

64-
return str_replace($file, array_get($data, 'src', $file), $resource);
56+
return str_replace($file, Arr::get($data, 'src') ?? $file, $resource);
6557
}
6658

6759
/**
@@ -77,7 +69,7 @@ public function integrity(string $resource): string
7769
$file = last(explode('/', $resource));
7870
$data = array_get($this->manifest(), $file, $file);
7971

80-
return array_get($data, 'integrity', '');
72+
return Arr::get($data, 'integrity') ?? '';
8173
}
8274

8375
/**
@@ -122,21 +114,8 @@ public function js(string $resource): string
122114
*/
123115
protected function manifest(): array
124116
{
125-
if (! is_null(self::$manifest)) {
126-
return self::$manifest;
127-
}
128-
129-
// Skip checking the cache if we are not in production.
130-
if ($this->application->environment() === 'production') {
131-
$stored = $this->cache->get('Core:AssetManifest');
132-
if (! is_null($stored)) {
133-
return self::$manifest = $stored;
134-
}
135-
}
136-
137-
$contents = json_decode($this->filesystem->get(self::MANIFEST_PATH), true);
138-
$this->cache->put('Core:AssetManifest', $contents, Chronos::now()->addMinutes(1440));
139-
140-
return self::$manifest = $contents;
117+
return self::$manifest ?: self::$manifest = json_decode(
118+
$this->filesystem->get(self::MANIFEST_PATH), true
119+
);
141120
}
142121
}

0 commit comments

Comments
 (0)