Skip to content

Commit

Permalink
MDL-63785 core_webservice: performance improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaies committed Dec 10, 2018
1 parent 66e1565 commit 29d0db8
Showing 1 changed file with 12 additions and 28 deletions.
40 changes: 12 additions & 28 deletions webservice/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,39 +115,23 @@ public static function get_contexts_for_userid(int $userid) : \core_privacy\loca
* @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination.
*/
public static function get_users_in_context(userlist $userlist) {
$context = $userlist->get_context();

$params = [
'contextid' => $context->id,
'contextuser' => CONTEXT_USER,
];

$sql = "SELECT ctx.instanceid as userid
FROM {external_tokens} t
JOIN {context} ctx
ON ctx.instanceid = t.userid
AND ctx.contextlevel = :contextuser
WHERE ctx.id = :contextid";
global $DB;

$userlist->add_from_sql('userid', $sql, $params);
$context = $userlist->get_context();

$sql = "SELECT ctx.instanceid as userid
FROM {external_tokens} t
JOIN {context} ctx
ON ctx.instanceid = t.creatorid
AND ctx.contextlevel = :contextuser
WHERE ctx.id = :contextid";
if (!$context instanceof \context_user) {
return;
}

$userlist->add_from_sql('userid', $sql, $params);
$userid = $context->instanceid;

$sql = "SELECT ctx.instanceid as userid
FROM {external_services_users} su
JOIN {context} ctx
ON ctx.instanceid = su.userid
AND ctx.contextlevel = :contextuser
WHERE ctx.id = :contextid";
$hasdata = false;
$hasdata = $hasdata || $DB->record_exists_select('external_tokens', 'userid = ? OR creatorid = ?', [$userid, $userid]);
$hasdata = $hasdata || $DB->record_exists('external_services_users', ['userid' => $userid]);

$userlist->add_from_sql('userid', $sql, $params);
if ($hasdata) {
$userlist->add_user($userid);
}
}

/**
Expand Down

0 comments on commit 29d0db8

Please sign in to comment.