Commit 4942c941 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Don't bother to pull user views from db on the find friends page


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent c9c4d236
......@@ -991,7 +991,7 @@ function get_new_username($desired) {
* @param $userlist the ids separated by commas
* @return array containing the users in the order from $userlist
*/
function get_users_data($userlist) {
function get_users_data($userlist, $getviews=true) {
global $USER;
$sql = 'SELECT u.id, 0 AS pending,
COALESCE((SELECT ap.value FROM {usr_account_preference} ap WHERE ap.usr = u.id AND ap.field = \'messages\'), \'allow\') AS messages,
......@@ -1026,31 +1026,32 @@ function get_users_data($userlist) {
$record->institutions = get_institution_string_for_user($record->id);
}
if (!$data || !$views = get_views(array_keys($data), null, null)) {
if (!$data || !$getviews || !$views = get_views(array_keys($data), null, null)) {
$views = array();
}
$viewcount = array_map('count', $views);
// since php is so special and inconsistent, we can't use array_map for this because it breaks the top level indexes.
$cleanviews = array();
foreach ($views as $userindex => $viewarray) {
$cleanviews[$userindex] = array_slice($viewarray, 0, 5);
// Don't reveal any more about the view than necessary
foreach ($cleanviews as $userviews) {
foreach ($userviews as &$view) {
foreach (array_keys(get_object_vars($view)) as $key) {
if ($key != 'id' && $key != 'title') {
unset($view->$key);
if ($getviews) {
$viewcount = array_map('count', $views);
// since php is so special and inconsistent, we can't use array_map for this because it breaks the top level indexes.
$cleanviews = array();
foreach ($views as $userindex => $viewarray) {
$cleanviews[$userindex] = array_slice($viewarray, 0, 5);
// Don't reveal any more about the view than necessary
foreach ($cleanviews as $userviews) {
foreach ($userviews as &$view) {
foreach (array_keys(get_object_vars($view)) as $key) {
if ($key != 'id' && $key != 'title') {
unset($view->$key);
}
}
}
}
}
}
foreach ($data as $friend) {
if (isset($cleanviews[$friend->id])) {
if ($getviews && isset($cleanviews[$friend->id])) {
$friend->views = $cleanviews[$friend->id];
}
if ($friend->pending) {
......
......@@ -41,7 +41,7 @@ $data = search_user($query, $limit, $offset, array('exclude' => $USER->get('id')
if ($data['data']) {
$userlist = join(',', array_map(create_function('$u','return $u[\'id\'];'), $data['data']));
$data['data'] = get_users_data($userlist);
$data['data'] = get_users_data($userlist, false);
}
$searchform = pieform(array(
......
Supports Markdown
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