mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-10 10:02:33 +03:00
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;
|
||||
}
|
||||
|
||||
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