Skip to content

Instantly share code, notes, and snippets.

@sminnee
Created March 11, 2010 03:32
Show Gist options
  • Select an option

  • Save sminnee/328783 to your computer and use it in GitHub Desktop.

Select an option

Save sminnee/328783 to your computer and use it in GitHub Desktop.
Index: subsites/code/Subsite.php
===================================================================
--- subsites/code/Subsite.php (revision 100863)
+++ subsites/code/Subsite.php (working copy)
@@ -74,6 +74,11 @@
*/
protected static $allowed_themes = array();
+ /**
+ * Memory cache of accessible sites
+ */
+ private static $_cache_accessible_sites = null;
+
static function set_allowed_domains($domain){
user_error('Subsite::set_allowed_domains() is deprecated; it is no longer necessary '
. 'because users can now enter any domain name', E_USER_NOTICE);
@@ -429,16 +434,23 @@
* @param $mainSiteTitle The label to give to the main site
*/
function accessible_sites($permCode, $includeMainSite = false, $mainSiteTitle = "Main site", $member = null) {
- // For 2.3 and 2.4 compatibility
- $q = defined('Database::USE_ANSI_SQL') ? "\"" : "`";
-
// Rationalise member arguments
if(!$member) $member = Member::currentUser();
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) . "'";
+
+ // For 2.3 and 2.4 compatibility
+ $q = defined('Database::USE_ANSI_SQL') ? "\"" : "`";
+
+ // Cache handling
+ $cacheKey = $SQL_codes . '-' . $member->ID;
+ if(isset(self::$_cache_accessible_sites[$cacheKey])) {
+ return self::$_cache_accessible_sites[$cacheKey];
+ }
$templateClassList = "'" . implode("', '", ClassInfo::subclassesFor("Subsite_Template")) . "'";
@@ -497,6 +509,8 @@
}
}
+ self::$_cache_accessible_sites[$cacheKey] = $subsites;
+
return $subsites;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment