Skip to content

Commit

Permalink
MDL-64782 core_badges: Performance improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaies committed Apr 23, 2019
1 parent 1916f2b commit 30ce76c
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions badges/classes/privacy/provider.php
Expand Up @@ -197,20 +197,21 @@ public static function get_users_in_context(userlist $userlist) {

if ($context->contextlevel == CONTEXT_COURSE || $context->contextlevel == CONTEXT_SYSTEM) {
// Find the modifications we made on badges (course & system).
$params = [
'courselevel' => CONTEXT_COURSE,
'syscontextid' => SYSCONTEXTID,
'typecourse' => BADGE_TYPE_COURSE,
'typesite' => BADGE_TYPE_SITE,
'contextid' => $context->id,
];
if ($context->contextlevel == CONTEXT_COURSE) {
$extrawhere = 'AND b.courseid = :courseid';
$params = [
'badgetype' => BADGE_TYPE_COURSE,
'courseid' => $context->instanceid
];
} else {
$extrawhere = '';
$params = ['badgetype' => BADGE_TYPE_SITE];
}

$sql = "SELECT b.usermodified, b.usercreated
FROM {badge} b
JOIN {context} ctx
ON (b.type = :typecourse AND b.courseid = ctx.instanceid AND ctx.contextlevel = :courselevel)
OR (b.type = :typesite AND ctx.id = :syscontextid)
WHERE ctx.id = :contextid";
WHERE b.type = :badgetype
$extrawhere";

$userlist->add_from_sql('usermodified', $sql, $params);
$userlist->add_from_sql('usercreated', $sql, $params);
Expand Down

0 comments on commit 30ce76c

Please sign in to comment.