Facebook  Twitter 

SMFHacks.com

+-

SMFHacks.com

+- User Information

Welcome, Guest.
Please login or register.
 
 
 
Forgot your password?

+- Forum Stats

Members
Total Members: 4255
Latest: andreios
New This Month: 3
New This Week: 1
New Today: 0
Stats
Total Posts: 43259
Total Topics: 7518
Most Online Today: 201
Most Online Ever: 2482
(April 09, 2011, 07:02:45 pm)
Users Online
Members: 0
Guests: 198
Total: 198

Author Topic: Is this the correct way to cache?  (Read 17038 times)

0 Members and 1 Guest are viewing this topic.

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
Is this the correct way to cache?
« on: June 06, 2018, 11:36:47 am »
Code: [Select]
// 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 />' => '&#10;')));
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 />' => '&#10;')));
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 .= '&nbsp;<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;

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 16436
    • View Profile
Re: Is this the correct way to cache?
« Reply #1 on: June 06, 2018, 12:02:27 pm »
I wouldu get rid of the else
by $context['topics'] = $temp;

Since it will either get from the cache or run the query
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
Re: Is this the correct way to cache?
« Reply #2 on: June 06, 2018, 12:18:05 pm »
Thank you

 

Related Topics

  Subject / Started by Replies Last post
0 Replies
4584 Views
Last post June 15, 2007, 03:17:11 am
by julien
0 Replies
3758 Views
Last post October 31, 2007, 03:43:11 pm
by sasawawa
0 Replies
3243 Views
Last post May 23, 2009, 10:35:41 am
by Paddleducks Forum - Damien
5 Replies
8399 Views
Last post April 02, 2011, 12:34:51 pm
by neforum
2 Replies
4374 Views
Last post August 06, 2016, 01:33:58 am
by shuban

+- Recent Topics

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

Powered by EzPortal