Skip to content

Commit

Permalink
MDL-61435 core_tag: improve get_tags_by_area_in_contexts performance
Browse files Browse the repository at this point in the history
  • Loading branch information
lameze committed Apr 3, 2018
1 parent 39fab18 commit 1399c7e
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions tag/classes/tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -1754,15 +1754,16 @@ public static function get_tags_by_area_in_contexts($component, $itemtype, array
list($contextsql, $contextsqlparams) = $DB->get_in_or_equal($contextids);
$params = array_merge($params, $contextsqlparams);

$subsql = "SELECT tagid
FROM {tag_instance}
$subsql = "SELECT DISTINCT t.id
FROM {tag} t
JOIN {tag_instance} ti ON t.id = ti.tagid
WHERE component = ?
AND itemtype = ?
AND contextid {$contextsql}
GROUP BY tagid";
$sql = "SELECT *
FROM {tag}
WHERE id IN ({$subsql})";
AND contextid {$contextsql}";

$sql = "SELECT tt.*
FROM ($subsql) tv
JOIN {tag} tt ON tt.id = tv.id";

return array_map(function($record) {
return new core_tag_tag($record);
Expand Down

0 comments on commit 1399c7e

Please sign in to comment.