Add 简化的缓存功能至新系统参数模块,减少查表

This commit is contained in:
兔姬桑
2021-01-25 16:22:38 -05:00
parent 2fd6b81e02
commit a49828e3bf
2 changed files with 12 additions and 13 deletions

View File

@@ -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');
}
}
}

View File

@@ -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();