BUGFIX: Added caching to Subsite::accessible_sites() (by sminnee, merged from r100872)

This commit is contained in:
Sam Minnee 2011-09-22 17:40:26 +02:00 committed by Ingo Schommer
parent 28f63853e1
commit 674f4bee27

View File

@ -70,6 +70,11 @@ class Subsite extends DataObject implements PermissionProvider {
'PrimaryDomain' => 'Primary Domain',
'IsPublic' => 'Active subsite',
);
/**
* Memory cache of accessible sites
*/
private static $_cache_accessible_sites = array();
/**
* @var array $allowed_themes Numeric array of all themes which are allowed to be selected for all subsites.
@ -476,8 +481,15 @@ JS;
if(!$member) return new DataObjectSet();
if(!is_object($member)) $member = DataObject::get_by_id('Member', $member);
// Rationalise permCode argument
if(is_array($permCode)) $SQL_codes = "'" . implode("', '", Convert::raw2sql($permCode)) . "'";
else $SQL_codes = "'" . Convert::raw2sql($permCode) . "'";
// Cache handling
$cacheKey = $SQL_codes . '-' . $member->ID . '-' . $includeMainSite . '-' . $mainSiteTitle;
if(isset(self::$_cache_accessible_sites[$cacheKey])) {
return self::$_cache_accessible_sites[$cacheKey];
}
$templateClassList = "'" . implode("', '", ClassInfo::subclassesFor("Subsite_Template")) . "'";
@ -536,6 +548,8 @@ JS;
$subsites->insertFirst($mainSite);
}
}
self::$_cache_accessible_sites[$cacheKey] = $subsites;
return $subsites;
}
@ -612,6 +626,13 @@ JS;
static function disable_subsite_filter($disabled = true) {
self::$disable_subsite_filter = $disabled;
}
/**
* Flush caches on database reset
*/
static function on_db_reset() {
self::$_cache_accessible_sites = array();
}
}
/**