perf: 优化saenv、config配置
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user