SMF Support > SMF 2.0.x Support
How to disable thread views?
Groovystar:
I don't believe we need them, and though they can be nice, we are having server load issues and I was wondering if disabling thread views sitewide would help lighten the load. How do I do it?
Arantor:
First, actually stop view counts updating, remove this from Display.php:
--- Code: --- // Add 1 to the number of views of this topic.
if (empty($_SESSION['last_read_topic']) || $_SESSION['last_read_topic'] != $topic)
{
$smcFunc['db_query']('', '
UPDATE {db_prefix}topics
SET num_views = num_views + 1
WHERE id_topic = {int:current_topic}',
array(
'current_topic' => $topic,
)
);
$_SESSION['last_read_topic'] = $topic;
}
--- End code ---
That will stop the real work of the view counts, and the real performance hit. Everything else after that is pure window-dressing.
There are two places we need to fix it, the topic view itself and the list of topics. Let's deal with the topic view itself first - Display.template.php. Your mileage may vary, I don't know how modified your file will be.
--- Code: (find) ---<span id="author">', $txt['author'], '</span>
', $txt['topic'], ': ', $context['subject'], ' (', $txt['read'], ' ', $context['num_views'], ' ', $txt['times'], ')
</h3>
--- End code ---
--- Code: (replace) ---<span id="author">', $txt['author'], '</span>
', $txt['topic'], ': ', $context['subject'], '
</h3>
--- End code ---
Now, let's fix the list of topics - MessageIndex.template.php. We need to fix two things here, the actual row itself and the header. Here's the changes from a stock install:
--- Code: (find) --- <td class="stats ', $color_class, '">
', $topic['replies'], ' ', $txt['replies'], '
<br />
', $topic['views'], ' ', $txt['views'], '
</td>
--- End code ---
--- Code: (replace) --- <td class="stats ', $color_class, '">
', $topic['replies'], ' ', $txt['replies'], '
</td>
--- End code ---
That's fixed the row itself, now to fix the header.
--- Code: (find) --- if (!empty($context['topics']))
{
echo '
<th scope="col" class="first_th" width="8%" colspan="2"> </th>
<th scope="col" class="lefttext"><a href="', $scripturl, '?board=', $context['current_board'], '.', $context['start'], ';sort=subject', $context['sort_by'] == 'subject' && $context['sort_direction'] == 'up' ? ';desc' : '', '">', $txt['subject'], $context['sort_by'] == 'subject' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" />' : '', '</a> / <a href="', $scripturl, '?board=', $context['current_board'], '.', $context['start'], ';sort=starter', $context['sort_by'] == 'starter' && $context['sort_direction'] == 'up' ? ';desc' : '', '">', $txt['started_by'], $context['sort_by'] == 'starter' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" />' : '', '</a></th>
<th scope="col" width="14%"><a href="', $scripturl, '?board=', $context['current_board'], '.', $context['start'], ';sort=replies', $context['sort_by'] == 'replies' && $context['sort_direction'] == 'up' ? ';desc' : '', '">', $txt['replies'], $context['sort_by'] == 'replies' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" />' : '', '</a> / <a href="', $scripturl, '?board=', $context['current_board'], '.', $context['start'], ';sort=views', $context['sort_by'] == 'views' && $context['sort_direction'] == 'up' ? ';desc' : '', '">', $txt['views'], $context['sort_by'] == 'views' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" />' : '', '</a></th>';
--- End code ---
--- Code: (replace) --- if (!empty($context['topics']))
{
echo '
<th scope="col" class="first_th" width="8%" colspan="2"> </th>
<th scope="col" class="lefttext"><a href="', $scripturl, '?board=', $context['current_board'], '.', $context['start'], ';sort=subject', $context['sort_by'] == 'subject' && $context['sort_direction'] == 'up' ? ';desc' : '', '">', $txt['subject'], $context['sort_by'] == 'subject' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" />' : '', '</a> / <a href="', $scripturl, '?board=', $context['current_board'], '.', $context['start'], ';sort=starter', $context['sort_by'] == 'starter' && $context['sort_direction'] == 'up' ? ';desc' : '', '">', $txt['started_by'], $context['sort_by'] == 'starter' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" />' : '', '</a></th>
<th scope="col" width="14%"><a href="', $scripturl, '?board=', $context['current_board'], '.', $context['start'], ';sort=replies', $context['sort_by'] == 'replies' && $context['sort_direction'] == 'up' ? ';desc' : '', '">', $txt['replies'], $context['sort_by'] == 'replies' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" />' : '', '</a></th>';
--- End code ---
As ever, backup first.
Groovystar:
Whoa, okay. A lot of codework there. :) Thank you so much! Will it actually reduce a lot of load to do this, though?
I have custom themes. Would I be disabling this in the default theme or also all the custom built themes as well?
Arantor:
It will save a query most times that people view threads, quite a saving really.
Most of the codework is really aesthetic rather than anything else, and yes you'd have to do it in any theme that has its own Display.template.php and/or MessageIndex.template.php files.
Groovystar:
Okay, thanks for letting me know.
I've never done a manual edit this extensive so I am a bit nervous. Would I do the files in the order you gave? I just want to avoid the site glitching out during it, no telling what the server will do if that happened.
Navigation
[0] Message Index
[#] Next page
Go to full version