From f6aee95cfc79d42524864715452f5b048e6288bd Mon Sep 17 00:00:00 2001 From: Ying Date: Thu, 1 Sep 2022 18:38:42 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96saenv=E3=80=81config?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/system/Config.php | 11 +++++++++-- app/functions.php | 10 +++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/common/model/system/Config.php b/app/common/model/system/Config.php index f42145c..30c4a66 100644 --- a/app/common/model/system/Config.php +++ b/app/common/model/system/Config.php @@ -36,11 +36,18 @@ class Config extends Model */ public static function all(string $name = '', bool $group = false): array { + $where = []; $config = []; - $where = $group ? ['group' => $name] : []; + + if (!empty($name) && $group) { + $where[] = ['group', '=', $name]; + } else { + if (!empty($name)) { + $where[] = ['name', '=', $name]; + } + } $list = self::where($where)->select()->toArray(); - foreach ($list as $option) { if (!is_empty($option['type']) && 'array' == trim($option['type'])) { $config[$option['name']] = json_decode($option['value'], true); diff --git a/app/functions.php b/app/functions.php index 2b5dafb..0cdd7ae 100644 --- a/app/functions.php +++ b/app/functions.php @@ -582,21 +582,21 @@ if (!function_exists('saenv')) { { $redis = 'config_' . $name; $config = Cache::get($redis); - try { - $configList = Cache::get('config_list') ?? []; if (empty($config)) { - $config = $group ? Config::all($name, true) : Config::where('name', $name)->value('value'); + $config = Config::all($name, $group); if (!empty($config)) { + // 是否开启分组查询 + if (empty($group)) { + $config = $config[$name]; + } $configList[$name] = $redis; Cache::set($redis, $config); Cache::set('config_list', $configList); } } - } catch (\Exception $e) {} - return $config; } }