mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-10888: groupings - added some caching of repetative queries
This commit is contained in:
parent
74df435726
commit
e0bc99e4db
1 changed files with 13 additions and 7 deletions
|
@ -136,7 +136,9 @@ function groups_is_member($groupid, $userid=null) {
|
||||||
*/
|
*/
|
||||||
function groups_has_membership($cm, $userid=null) {
|
function groups_has_membership($cm, $userid=null) {
|
||||||
global $CFG, $USER;
|
global $CFG, $USER;
|
||||||
|
|
||||||
|
static $cache = array();
|
||||||
|
|
||||||
// groupings are ignored when not enabled
|
// groupings are ignored when not enabled
|
||||||
if (empty($CFG->enablegroupings)) {
|
if (empty($CFG->enablegroupings)) {
|
||||||
$cm->groupingid = 0;
|
$cm->groupingid = 0;
|
||||||
|
@ -146,6 +148,11 @@ function groups_has_membership($cm, $userid=null) {
|
||||||
$userid = $USER->id;
|
$userid = $USER->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$cachekey = $userid.'|'.$cm->course.'|'.$cm->groupingid;
|
||||||
|
if (isset($cache[$cachekey])) {
|
||||||
|
return($cache[$cachekey]);
|
||||||
|
}
|
||||||
|
|
||||||
if ($cm->groupingid) {
|
if ($cm->groupingid) {
|
||||||
// find out if member of any group in selected activity grouping
|
// find out if member of any group in selected activity grouping
|
||||||
$sql = "SELECT 'x'
|
$sql = "SELECT 'x'
|
||||||
|
@ -158,8 +165,10 @@ function groups_has_membership($cm, $userid=null) {
|
||||||
FROM {$CFG->prefix}groups_members gm, {$CFG->prefix}groups g
|
FROM {$CFG->prefix}groups_members gm, {$CFG->prefix}groups g
|
||||||
WHERE gm.userid = $userid AND gm.groupid = g.id AND g.courseid = {$cm->course}";
|
WHERE gm.userid = $userid AND gm.groupid = g.id AND g.courseid = {$cm->course}";
|
||||||
}
|
}
|
||||||
|
|
||||||
return record_exists_sql($sql);
|
$cache[$cachekey] = record_exists_sql($sql);
|
||||||
|
|
||||||
|
return $cache[$cachekey];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -350,10 +359,7 @@ function groups_course_module_visible($cm, $userid=null) {
|
||||||
if (empty($cm->groupmembersonly)) {
|
if (empty($cm->groupmembersonly)) {
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
if (has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_MODULE, $cm->id), $userid)) {
|
if (groups_has_membership($cm, $userid) || has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_MODULE, $cm->id), $userid)) {
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
if (groups_has_membership($cm, $userid)) {
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
return(false);
|
return(false);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue