mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-11 15:10:54 +00:00
Add 简化的缓存功能至新系统参数模块,减少查表
This commit is contained in:
@@ -2,22 +2,17 @@
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Components\Helpers;
|
||||
use App\Models\Config;
|
||||
use Artisan;
|
||||
use Cache;
|
||||
|
||||
class ConfigObserver
|
||||
{
|
||||
public function updated(Config $config): void
|
||||
public function updated(Config $config) // 更新设定
|
||||
{
|
||||
// 域名出现变动,更新路由设定
|
||||
if (in_array($config->name, ['subscribe_domain', 'web_api_url', 'website_callback_url'])) {
|
||||
if (config('app.debug')) {
|
||||
Artisan::call('optimize:clear');
|
||||
} else {
|
||||
Artisan::call('optimize');
|
||||
}
|
||||
if (config('app.debug')) {
|
||||
Artisan::call('optimize:clear');
|
||||
} else {
|
||||
Artisan::call('optimize');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Providers;
|
||||
use App\Channels\BarkChannel;
|
||||
use App\Channels\ServerChanChannel;
|
||||
use App\Models\Config;
|
||||
use Cache;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use NotificationChannels\BearyChat\BearyChatChannel;
|
||||
use NotificationChannels\Telegram\TelegramChannel;
|
||||
@@ -35,13 +36,16 @@ class SettingServiceProvider extends ServiceProvider
|
||||
'ticket_replied_notification',
|
||||
]);
|
||||
$payments = ['is_AliPay', 'is_QQPay', 'is_WeChatPay', 'is_otherPay'];
|
||||
$settings = Config::all();
|
||||
if (! Cache::has('settings')) {
|
||||
Cache::forever('settings', Config::whereNotNull('value')->get());
|
||||
}
|
||||
$settings = Cache::get('settings');
|
||||
$modified = $settings
|
||||
->whereNotIn('name', $toApp->keys()->merge($notifications)) // 设置一般系统选项
|
||||
->pluck('value', 'name')
|
||||
->merge($settings->whereIn('name', $notifications)->pluck('value', 'name')->map(function ($item) {
|
||||
return self::setChannel(json_decode($item, true) ?? []);
|
||||
})) // 设置通知相关选项
|
||||
return self::setChannel(json_decode($item, true)); // 设置通知相关选项
|
||||
}))
|
||||
->merge(collect(['is_onlinePay' => $settings->whereIn('name', $payments)->pluck('value')->filter()->isNotEmpty()])) // 设置在线支付开关
|
||||
->sortKeys()
|
||||
->toArray();
|
||||
|
||||
Reference in New Issue
Block a user