Commit af140a73 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Two minor optimisations to get_extra_view_info



In many places get_extra_view_info is used when a user is searching
their own views.  In these cases the user record is already easily
available, and we don't need to query it again.

The tags query is also made optional.

Change-Id: Ib18ab9029c0bc243f92c763ac1ccf24b8d69ac17
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 6c6c24e7
......@@ -3391,7 +3391,7 @@ class View {
}
public static function get_extra_view_info(&$viewdata, $getartefacts = true) {
public static function get_extra_view_info(&$viewdata, $getartefacts=true, $gettags=true) {
if ($viewdata) {
// Get view owner details for display
$owners = array();
......@@ -3433,15 +3433,33 @@ class View {
}
}
}
$tags = get_records_select_array('view_tag', 'view IN (' . $viewidlist . ')');
if ($tags) {
foreach ($tags as &$tag) {
$viewdata[$tag->view]->tags[] = $tag->tag;
if ($gettags) {
$tags = get_records_select_array('view_tag', 'view IN (' . $viewidlist . ')');
if ($tags) {
foreach ($tags as &$tag) {
$viewdata[$tag->view]->tags[] = $tag->tag;
}
}
}
if (!empty($owners)) {
$owners = get_records_select_assoc('usr', 'id IN (' . join(',', $owners) . ')', null, '',
'id,username,firstname,lastname,preferredname,admin,staff,studentid,email,profileicon,urlid');
global $USER;
$userid = $USER->get('id');
$fields = array(
'id', 'username', 'firstname', 'lastname', 'preferredname', 'admin', 'staff', 'studentid', 'email',
'profileicon', 'urlid',
);
if (count($owners) == 1 && isset($owners[$userid])) {
$owners = array($userid => new StdClass);
foreach ($fields as $f) {
$owners[$userid]->$f = $USER->get($f);
}
}
else {
$owners = get_records_select_assoc(
'usr', 'id IN (' . join(',', array_fill(0, count($owners), '?')) . ')', $owners, '',
join(',', $fields)
);
}
}
if (!empty($groups)) {
require_once('group.php');
......
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