Topic: Optimise get_company_pref()
The file admin/db/company_db.inc has the function get_company_pref($prefs = null):
function get_company_pref($prefs = null)
{
global $SysPrefs, $db_version;
if (!isset($SysPrefs->prefs)) // just after first login or reset
$SysPrefs->refresh();
$all = $SysPrefs->prefs;
if (!$prefs)
return $all;
elseif (is_string($prefs))
return @$all[$prefs];
$ret = array();
foreach($prefs as $name)
$ret[$name] = $all[$name];
return $ret;
}
This can be simplified and made efficient by replacing it with:
function get_company_pref($prefs = null){
global $SysPrefs, $db_version;
if (!isset($SysPrefs->prefs)) // just after first login or reset
$SysPrefs->refresh();
$all = $SysPrefs->prefs;
if ($prefs && is_string($prefs))
return @$all[$prefs]; // silent on absent array element
if (!is_array($all))
$all = array();
return $all;}