Add in-request caching of vars that we've already looked up. We're

still doing too many database queries, but this cuts down some dupes.
This commit is contained in:
Bharat Mediratta
2009-03-07 04:44:16 +00:00
parent e96e26a12f
commit 3356091b65
+8 -1
View File
@@ -26,6 +26,7 @@
class module_Core {
public static $module_names = array();
public static $modules = array();
public static $var_cache = array();
static function get_version($module_name) {
return ORM::factory("module")->where("name", $module_name)->find()->version;
@@ -217,11 +218,17 @@ class module_Core {
* @return the value
*/
static function get_var($module_name, $name, $default_value=null) {
if (isset(self::$var_cache[$module_name][$name])) {
return self::$var_cache[$module_name][$name];
}
$var = ORM::factory("var")
->where("module_name", $module_name)
->where("name", $name)
->find();
return $var->loaded ? $var->value : $default_value;
self::$var_cache[$module_name][$name] = $var->loaded ? $var->value : $default_value;
return self::$var_cache[$module_name][$name];
}
/**