introduce a cached version of te ACL checking

for iterating over media namespaces
This commit is contained in:
Andreas Gohr 2014-08-01 12:04:35 +02:00
parent d347c5be0e
commit bfe414a661
2 changed files with 32 additions and 1 deletions

View File

@ -47,7 +47,7 @@ class MediaFile {
$this->id = cleanID($this->id);
$this->isexternal = false;
$this->file = mediaFN($this->id);
$this->auth = auth_quickaclcheck(getNS($this->id).':*');
$this->auth = auth_quickaclcheck_cached(getNS($this->id).':*');
}
}

View File

@ -652,6 +652,37 @@ function auth_isMember($memberlist, $user, array $groups) {
return false;
}
/**
* Caching wrapper around auth_quickaclcheck()
*
* This will check ACLs only once per request for the given ID. This is mostly useful when iterating over
* a larger list of media files in the same namespace. When in doubt, use the uncached variant!
*
* Cache is done in memory (static variable)
*
* @uthor Andreas Gohr <andi@splitbrain.org>
* @param string $id page ID (needs to be resolved and cleaned)
* @return int permision level
*/
function auth_quickaclcheck_cached($id) {
/* @var Input $INPUT */
global $INPUT;
$user = $INPUT->server->str('REMOTE_USER');
// cache initialization
// the cache is user based even though the user should not change within a request this is
// an additional safe guard
static $aclcache = array();
if(!isset($aclcache[$user])) $aclcache[$user] = array();
// fill cache
if(!isset($aclcache[$user][$id])) {
$aclcache[$user][$id] = auth_quickaclcheck($id);
}
return $aclcache[$user][$id];
}
/**
* Convinience function for auth_aclcheck()
*