浏览代码

Update InstanceService, fix banner blurhash memory bug

Daniel Supernault 2 年之前
父节点
当前提交
3aad75abcf
共有 3 个文件被更改,包括 17 次插入1 次删除
  1. 1 0
      app/Services/ConfigCacheService.php
  2. 12 1
      app/Services/InstanceService.php
  3. 4 0
      config/instance.php

+ 1 - 0
app/Services/ConfigCacheService.php

@@ -69,6 +69,7 @@ class ConfigCacheService
 				'instance.landing.show_directory',
 				'instance.landing.show_directory',
 				'instance.landing.show_explore',
 				'instance.landing.show_explore',
 				'instance.admin.pid',
 				'instance.admin.pid',
+				'instance.banner.blurhash'
 				// 'system.user_mode'
 				// 'system.user_mode'
 			];
 			];
 
 

+ 12 - 1
app/Services/InstanceService.php

@@ -5,6 +5,7 @@ namespace App\Services;
 use Cache;
 use Cache;
 use App\Instance;
 use App\Instance;
 use App\Util\Blurhash\Blurhash;
 use App\Util\Blurhash\Blurhash;
+use App\Services\ConfigCacheService;
 
 
 class InstanceService
 class InstanceService
 {
 {
@@ -13,7 +14,7 @@ class InstanceService
 	const CACHE_KEY_UNLISTED_DOMAINS = 'instances:unlisted:domains';
 	const CACHE_KEY_UNLISTED_DOMAINS = 'instances:unlisted:domains';
 	const CACHE_KEY_NSFW_DOMAINS = 'instances:auto_cw:domains';
 	const CACHE_KEY_NSFW_DOMAINS = 'instances:auto_cw:domains';
 	const CACHE_KEY_STATS = 'pf:services:instances:stats';
 	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)
 	public static function getByDomain($domain)
 	{
 	{
@@ -83,10 +84,18 @@ class InstanceService
 
 
     public static function headerBlurhash()
     public static function headerBlurhash()
     {
     {
+		ini_set('memory_limit', config('pixelfed.memory_limit', '1024M'));
+
     	return Cache::rememberForever(self::CACHE_KEY_BANNER_BLURHASH, function() {
     	return Cache::rememberForever(self::CACHE_KEY_BANNER_BLURHASH, function() {
     		if(str_ends_with(config_cache('app.banner_image'), 'headers/default.jpg')) {
     		if(str_ends_with(config_cache('app.banner_image'), 'headers/default.jpg')) {
     			return 'UzJR]l{wHZRjM}R%XRkCH?X9xaWEjZj]kAjt';
     			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'));
 			$file = config_cache('app.banner_image') ?? url(Storage::url('public/headers/default.jpg'));
 
 
 			$image = imagecreatefromstring(file_get_contents($file));
 			$image = imagecreatefromstring(file_get_contents($file));
@@ -115,6 +124,8 @@ class InstanceService
 				return 'UzJR]l{wHZRjM}R%XRkCH?X9xaWEjZj]kAjt';
 				return 'UzJR]l{wHZRjM}R%XRkCH?X9xaWEjZj]kAjt';
 			}
 			}
 
 
+			ConfigCacheService::put('instance.banner.blurhash', $blurhash);
+
 			return $blurhash;
 			return $blurhash;
     	});
     	});
     }
     }

+ 4 - 0
config/instance.php

@@ -124,5 +124,9 @@ return [
 	'landing' => [
 	'landing' => [
 		'show_directory' => env('INSTANCE_LANDING_SHOW_DIRECTORY', true),
 		'show_directory' => env('INSTANCE_LANDING_SHOW_DIRECTORY', true),
 		'show_explore' => env('INSTANCE_LANDING_SHOW_EXPLORE', true),
 		'show_explore' => env('INSTANCE_LANDING_SHOW_EXPLORE', true),
+	],
+
+	'banner' => [
+		'blurhash' => env('INSTANCE_BANNER_BLURHASH', 'UzJR]l{wHZRjM}R%XRkCH?X9xaWEjZj]kAjt')
 	]
 	]
 ];
 ];