diff --git a/app/Services/ConfigCacheService.php b/app/Services/ConfigCacheService.php index 23b762486..7ecb318e0 100644 --- a/app/Services/ConfigCacheService.php +++ b/app/Services/ConfigCacheService.php @@ -69,6 +69,7 @@ class ConfigCacheService 'instance.landing.show_directory', 'instance.landing.show_explore', 'instance.admin.pid', + 'instance.banner.blurhash' // 'system.user_mode' ]; diff --git a/app/Services/InstanceService.php b/app/Services/InstanceService.php index c2a33a888..85c5ed69a 100644 --- a/app/Services/InstanceService.php +++ b/app/Services/InstanceService.php @@ -5,6 +5,7 @@ namespace App\Services; use Cache; use App\Instance; use App\Util\Blurhash\Blurhash; +use App\Services\ConfigCacheService; class InstanceService { @@ -13,7 +14,7 @@ class InstanceService const CACHE_KEY_UNLISTED_DOMAINS = 'instances:unlisted:domains'; const CACHE_KEY_NSFW_DOMAINS = 'instances:auto_cw:domains'; const CACHE_KEY_STATS = 'pf:services:instances:stats'; - const CACHE_KEY_BANNER_BLURHASH = 'pf:services:instance:header-blurhash'; + const CACHE_KEY_BANNER_BLURHASH = 'pf:services:instance:header-blurhash:v1'; public static function getByDomain($domain) { @@ -83,10 +84,18 @@ class InstanceService public static function headerBlurhash() { + ini_set('memory_limit', config('pixelfed.memory_limit', '1024M')); + return Cache::rememberForever(self::CACHE_KEY_BANNER_BLURHASH, function() { if(str_ends_with(config_cache('app.banner_image'), 'headers/default.jpg')) { return 'UzJR]l{wHZRjM}R%XRkCH?X9xaWEjZj]kAjt'; } + $cached = config_cache('instance.banner.blurhash'); + + if($cached && $cached !== 'UzJR]l{wHZRjM}R%XRkCH?X9xaWEjZj]kAjt') { + return $cached; + } + $file = config_cache('app.banner_image') ?? url(Storage::url('public/headers/default.jpg')); $image = imagecreatefromstring(file_get_contents($file)); @@ -115,6 +124,8 @@ class InstanceService return 'UzJR]l{wHZRjM}R%XRkCH?X9xaWEjZj]kAjt'; } + ConfigCacheService::put('instance.banner.blurhash', $blurhash); + return $blurhash; }); } diff --git a/config/instance.php b/config/instance.php index 9d10e2107..5161ecb80 100644 --- a/config/instance.php +++ b/config/instance.php @@ -124,5 +124,9 @@ return [ 'landing' => [ 'show_directory' => env('INSTANCE_LANDING_SHOW_DIRECTORY', true), 'show_explore' => env('INSTANCE_LANDING_SHOW_EXPLORE', true), + ], + + 'banner' => [ + 'blurhash' => env('INSTANCE_BANNER_BLURHASH', 'UzJR]l{wHZRjM}R%XRkCH?X9xaWEjZj]kAjt') ] ];