Commit 5fb3ede1 authored by Nigel McNie's avatar Nigel McNie
Browse files

Implement caching in group_is_only_admin.

parent 4423c1e9
......@@ -78,7 +78,7 @@ function group_user_access($groupid, $userid=null) {
* @returns boolean
*/
function group_is_only_admin($groupid, $userid=null) {
// TODO: caching
static $result;
$groupid = (int)$groupid;
......@@ -98,8 +98,12 @@ function group_is_only_admin($groupid, $userid=null) {
throw new InvalidArgumentException("group_is_only_admin: user argument should be an integer");
}
return group_user_access($groupid, $userid) == 'admin'
&& count_records('group_member', 'group', $groupid, 'role', 'admin') == 1;
if (isset($result[$groupid][$userid])) {
return $result[$groupid][$userid];
}
return $result[$groupid][$userid] = (group_user_access($groupid, $userid) == 'admin'
&& count_records('group_member', 'group', $groupid, 'role', 'admin') == 1);
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment