|
Forum > General SMF Forum
Is this the correct way to cache?
(1/1)
shuban:
--- Code: ---// Let's cache the results to load faster... if (($temp = cache_get_data('latest_topics', 480)) == null) { $request = db_query(" SELECT $select_clause FROM {$db_prefix}topics AS t INNER JOIN {$db_prefix}messages AS ml ON (ml.ID_MSG = t.ID_LAST_MSG) INNER JOIN {$db_prefix}messages AS mso ON (mso.ID_MSG = t.ID_FIRST_MSG) LEFT JOIN {$db_prefix}boards AS b ON (b.ID_BOARD = ml.ID_BOARD) LEFT JOIN {$db_prefix}members AS meml ON (meml.ID_MEMBER = ml.ID_MEMBER) LEFT JOIN {$db_prefix}log_topics AS lt ON (lt.ID_TOPIC = ml.ID_TOPIC AND lt.ID_MEMBER = " . $ID_MEMBER .") LEFT JOIN {$db_prefix}log_mark_read AS lmr ON (lmr.ID_BOARD = t.ID_BOARD AND lmr.ID_MEMBER = " . $ID_MEMBER .") WHERE t." . $query_this_board . " AND t.ID_LAST_MSG >= " . $min_message ." ".$time_frame." ORDER BY " . $_REQUEST['sort'] . ($ascending ? '' : ' DESC') ." LIMIT $_REQUEST[start], $modSettings[defaultMaxTopics]", __FILE__, __LINE__);
$context['topics'] = array(); $topic_ids = array(); while ($row = mysql_fetch_assoc($request)) { if ($row['ID_POLL'] > 0 && $modSettings['pollMode'] == '0') continue;
$topic_ids[] = $row['ID_TOPIC'];
// * NiceTooltips mod $row['nice_tooltip_first_msg'] = NiceTooltip($row['first_body'], $row['first_subject'], $row['first_smileys'], $row['ID_FIRST_MSG']); // Limit them to 128 characters - do this FIRST because it's a lot of wasted censoring otherwise. $row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['ID_FIRST_MSG']), array('<br />' => ' '))); if ($func['strlen']($row['first_body']) > 128) $row['first_body'] = $func['substr']($row['first_body'], 0, 128) . '...'; $row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['ID_LAST_MSG']), array('<br />' => ' '))); if ($func['strlen']($row['last_body']) > 128) $row['last_body'] = $func['substr']($row['last_body'], 0, 128) . '...';
// Censor the subject and message preview. censorText($row['first_subject']); censorText($row['first_body']);
// Don't censor them twice! if ($row['ID_FIRST_MSG'] == $row['ID_LAST_MSG']) { $row['last_subject'] = $row['first_subject']; $row['last_body'] = $row['first_body']; } else { censorText($row['last_subject']); censorText($row['last_body']); }
// Decide how many pages the topic should have. $topic_length = $row['numReplies'] + 1; if ($topic_length > $modSettings['defaultMaxMessages']) { $tmppages = array(); $tmpa = 1; for ($tmpb = 0; $tmpb < $topic_length; $tmpb += $modSettings['defaultMaxMessages']) { $tmppages[] = '<a style="margin: 0 1px;" href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.' . $tmpb . '">' . $tmpa . '</a>'; $tmpa++; } // Show links to all the pages? if (count($tmppages) <= 5) $pages = '<img style="vertical-align: middle;" src="'.$settings['default_theme_url'].'/images/page-small.png"> ' . implode('', $tmppages); // Or skip a few? else $pages = '<img style="vertical-align: middle;" src="'.$settings['default_theme_url'].'/images/page-small.png"> ' . $tmppages[0] . $tmppages[1] . '...' . $tmppages[count($tmppages) - 2] . $tmppages[count($tmppages) - 1];
if (!empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages']) $pages .= ' <a style="margin: 0 1px;" href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0;all">' . $txt['190'] . '</a>'; $pages .= ''; } else $pages = '';
// We need to check the topic icons exist... you can never be too sure! if (empty($modSettings['messageIconChecks_disable'])) { // First icon first... as you'd expect. if (!isset($context['icon_sources'][$row['first_icon']])) $context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.gif') ? 'images_url' : 'default_images_url'; // Last icon... last... duh. if (!isset($context['icon_sources'][$row['last_icon']])) $context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.gif') ? 'images_url' : 'default_images_url'; }
// And build the array. $context['topics'][$row['ID_TOPIC']] = array( 'id' => $row['ID_TOPIC'], 'first_post' => array( 'id' => $row['id_msg_first'], 'member' => array( 'name' => $row['first_poster_name'], 'id' => $row['id_first_member'], 'href' => $scripturl . '?action=profile;u=' . $row['id_first_member'], 'link' => ($row['id_first_member'] != 0) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_first_member'] . '">' . $row['first_poster_name'] . '</a>' : $row['first_poster_name'], ), 'time' => timeformat($row['first_poster_time']), 'timestamp' => forum_time(true, $row['first_poster_time']), 'subject' => $row['first_subject'], 'preview' => $row['first_body'], 'icon' => $row['first_icon'], 'icon_url' => $settings[$context['icon_sources'][$row['first_icon']]] . '/post/' . $row['first_icon'] . '.gif', 'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0', 'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">' . $row['first_subject'] . '</a>', 'tooltip' => $row['nice_tooltip_first_msg'], ), 'last_post' => array( 'id' => $row['ID_LAST_MSG'], 'member' => array( 'name' => $row['last_poster_name'], 'id' => $row['id_last_member'], 'href' => $scripturl . '?action=profile;u=' . $row['id_last_member'], 'link' => ($row['id_last_member'] != 0) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_last_member'] . '">' . $row['last_poster_name'] . '</a>' : $row['last_poster_name'], ), 'time' => timeformat($row['last_poster_time']), 'timestamp' => forum_time(true, $row['last_poster_time']), 'subject' => $row['last_subject'], 'preview' => $row['last_body'], 'icon' => $row['last_icon'], 'icon_url' => $settings[$context['icon_sources'][$row['last_icon']]] . '/post/' . $row['last_icon'] . '.gif', 'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . ($row['numReplies'] == 0 ? '.0' : '.msg' . $row['ID_LAST_MSG']) . '#msg' . $row['ID_LAST_MSG'], 'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . ($row['numReplies'] == 0 ? '.0' : '.msg' . $row['ID_LAST_MSG']) . '#msg' . $row['ID_LAST_MSG'] . '" rel="nofollow">' . $row['last_subject'] . '</a>' ), 'is_new' => $row['is_new'] && !$user_info['is_guest'], 'new_href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . '#new', 'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . ($row['numReplies'] == 0 ? '.0' : '.msg' . $row['ID_MSG']) . '' . ($row['numReplies'] == 0 ? '' : 'new'), 'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . ($row['numReplies'] == 0 ? '.0' : '.msg' . $row['ID_MSG']) . '#msg' . $row['ID_MSG'] . '" rel="nofollow">' . $row['first_subject'] . '</a>', 'is_sticky' => !empty($modSettings['enableStickyTopics']) && !empty($row['isSticky']), 'is_locked' => !empty($row['locked']), 'is_poll' => $modSettings['pollMode'] == '1' && $row['ID_POLL'] > 0, 'is_hot' => $row['numReplies'] >= $modSettings['hotTopicPosts'], 'is_very_hot' => $row['numReplies'] >= $modSettings['hotTopicVeryPosts'], 'is_posted_in' => false, 'icon' => $row['first_icon'], 'icon_url' => $settings[$context['icon_sources'][$row['first_icon']]] . '/post/' . $row['first_icon'] . '.gif', 'subject' => $row['first_subject'], 'pages' => $pages, 'replies' => $row['numReplies'], 'views' => $row['numViews'], 'board' => array( 'id' => $row['ID_BOARD'], 'name' => $row['bname'], 'href' => $scripturl . '?board=' . $row['ID_BOARD'] . '.0', 'link' => '<a href="' . $scripturl . '?board=' . $row['ID_BOARD'] . '.0">' . $row['bname'] . '</a>' ) );
determineTopicClass($context['topics'][$row['ID_TOPIC']]); }
mysql_free_result($request);
cache_put_data('latest_topics', $context['topics'], 480); } else $context['topics'] = $temp; --- End code ---
SMFHacks:
I wouldu get rid of the else by $context['topics'] = $temp;
Since it will either get from the cache or run the query
shuban:
Thank you
Navigation
[0] Message Index |
No thumbnails on new uploads
by SMFHacks
March 27, 2024, 02:10:41 pm
|
Display the Contact Page for guests
by SMFHacks
March 27, 2024, 10:55:43 am
|
is it possible to add support for odysee.com
by fvlog19
March 21, 2024, 08:47:51 am
|
Request for admin notification
by davejo
March 10, 2024, 01:31:59 am
|
I need help with torrent upload
by Ineedsmfhelp
March 09, 2024, 10:01:13 pm
|
an idea for new mod (( content type with different display ))
by SMFHacks
February 27, 2024, 01:36:27 pm
|
[Mod] RSS Feed Poster
by SMFHacks
February 27, 2024, 11:57:18 am
|
find duplicate pictures
by fvlog19
February 14, 2024, 02:22:40 pm
|
Error uploading video.
by SMFHacks
February 08, 2024, 02:04:16 pm
|
Gallery icon as last added image
by fvlog19
February 01, 2024, 01:04:56 pm
|
|
|