SimplePortal

Development => Bugs => Fixed or Bogus Bugs => Topic started by: inter on September 09, 2012, 09:34:37 AM

Title: $members[] = array(...
Post by: inter on September 09, 2012, 09:34:37 AM
sorry my English  :)

Code: [Select]
SELECT ...
m.id_member, m.real_name, m.posts, m.avatar,
a.id_attach, a.attachment_type, a.filename, ...
FROM {db_prefix}members AS m ...

...
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if (!empty($row['id_member']))
$colorids[$row['id_member']] = $row['id_member'];

if ($modSettings['avatar_action_too_large'] == 'option_html_resize' || $modSettings['avatar_action_too_large'] == 'option_js_resize')
{
$avatar_width = !empty($modSettings['avatar_max_width_external']) ? ' width="' . $modSettings['avatar_max_width_external'] . '"' : '';
$avatar_height = !empty($modSettings['avatar_max_height_external']) ? ' height="' . $modSettings['avatar_max_height_external'] . '"' : '';
}
else
{
$avatar_width = '';
$avatar_height = '';
}

$members[] = array(
'id' => $row['id_member'],
'name' => $row['real_name'],
'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
'posts' => comma_format($row['posts']),
'avatar' => array(
'name' => $row['avatar'],
'image' => $row['avatar'] == '' ? ($row['id_attach'] > 0 ? '<img src="' . (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" class="avatar" border="0" />' : '') : (stristr($row['avatar'], 'http://') ? '<img src="' . $row['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="" class="avatar" border="0" />' : '<img src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" class="avatar" border="0" />'),
'href' => $row['avatar'] == '' ? ($row['id_attach'] > 0 ? (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) : '') : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar']),
'url' => $row['avatar'] == '' ? '' : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar'])
),
);
...
This code is often repeated
why should I care if you can pull the IDs and drive them in the loop as a function loadMemberData.

For Example:
Code: [Select]
...

SELECT m.id_member, a.filename, ...
FROM {db_prefix}members AS m ...

while ($row = $smcFunc['db_fetch_assoc']($request))
{
if (!empty($row['id_member']))
$all_posters[] = $row['id_member'];
}

$posters = array_unique($all_posters);
if (!empty($posters))
$context['my_posters'] = loadMemberData($posters);
...

you yourself think how many times you check information about Avtar and other information - in fact it can be done only once for each user and receive data globally throughout the script
Title: Re: $members[] = array(...
Post by: [SiNaN] on September 09, 2012, 10:33:15 AM
If you can get all the information you need with only a single lightweight query, it doesn't make sense to use two especially when the second one gathers a bunch of other unused data.
Title: Re: $members[] = array(...
Post by: inter on September 10, 2012, 05:54:46 AM
hmm...
I think I was wrong :P
if you change the display format (eg avatar) then all your code to alter.
need a common feature with the hook that it was possible to change data
SimplePortal 2.3.8 © 2008-2024, SimplePortal