forked from mirrors/easyappointments
Added caching to the settings helper so that we avoid unnecessary queries to the database.
This commit is contained in:
parent
e071ec46dc
commit
775d385e09
1 changed files with 13 additions and 2 deletions
|
@ -45,6 +45,8 @@ if ( ! function_exists('setting'))
|
|||
throw new InvalidArgumentException('The $key argument cannot be empty.');
|
||||
}
|
||||
|
||||
$cache = config('settings');
|
||||
|
||||
if (is_array($key))
|
||||
{
|
||||
foreach ($key as $name => $value)
|
||||
|
@ -60,13 +62,22 @@ if ( ! function_exists('setting'))
|
|||
}
|
||||
|
||||
$CI->settings_model->save($setting);
|
||||
|
||||
$cache[$name] = $value;
|
||||
}
|
||||
|
||||
config(['settings' => $cache]);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$setting = $CI->settings_model->query()->where('name', $key)->get()->row_array();
|
||||
if (empty($cache[$key]))
|
||||
{
|
||||
$setting = $CI->settings_model->query()->where('name', $key)->get()->row_array();
|
||||
|
||||
return $setting['value'] ?? $default;
|
||||
$cache[$key] = $setting['value'] ?? NULL;
|
||||
}
|
||||
|
||||
return $cache[$key] ?? $default;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue