Mattwhf
10-06-2016, 12:54 AM
Hello,
I read the log file and it noticed me this Mysql command is making my forum slow, with more than 15 seconds to query it.
I found it in an addon that I am using on my forum
$rcthrds = $vbulletin->db->query_read("
SELECT thread.threadid, thread.title, thread.lastpost, thread.lastpostid, thread.forumid, thread.lastposter, thread.lastposterid, thread.postusername, thread.dateline, thread.views, thread.replycount, thread.visible, thread.open, thread.prefixid, forum.title AS forumtitle, user.username, user.userid, user.usergroupid, user.displaygroupid, user.avatarid, user2.avatarid AS avatarid2
" . iif($vbulletin->options['threadpreview'], ",post.pagetext AS preview") . "
" . iif($vbulletin->options['avatarenabled'], ',avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline') . "
" . iif($vbulletin->options['avatarenabled'], ',avatar2.avatarpath AS avatarpath2, NOT ISNULL(customavatar2.userid) AS hascustomavatar2, customavatar2.dateline AS avatardateline2') . "
FROM " . TABLE_PREFIX . "thread AS thread
LEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.username = thread.postusername)
LEFT JOIN " . TABLE_PREFIX . "user AS user2 ON (user2.username = thread.lastposter)
INNER JOIN " . TABLE_PREFIX . "forum AS forum ON (forum.forumid = thread.forumid)
" . iif($vbulletin->options['threadpreview'], "LEFT JOIN " . TABLE_PREFIX . "post AS post ON (post.postid = thread.firstpostid)") . "
" . iif($vbulletin->options['avatarenabled'], "LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON(avatar.avatarid = user.avatarid) LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON(customavatar.userid = user.userid)") . "
" . iif($vbulletin->options['avatarenabled'], "LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar2 ON(avatar2.avatarid = user2.avatarid) LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar2 ON(customavatar2.userid = user2.userid)") . "
WHERE NOT ISNULL(thread.threadid) AND thread.visible = '1' AND thread.open!='10' $forumfilter
ORDER BY rand(), lastpost DESC
LIMIT 0, {$vbulletin->options['rcmt_reclimit']}
");
I think this command
ORDER BY rand(), lastpost DESC
is the reason caused slow queries on my forum.
How to fix this?
I read the log file and it noticed me this Mysql command is making my forum slow, with more than 15 seconds to query it.
I found it in an addon that I am using on my forum
$rcthrds = $vbulletin->db->query_read("
SELECT thread.threadid, thread.title, thread.lastpost, thread.lastpostid, thread.forumid, thread.lastposter, thread.lastposterid, thread.postusername, thread.dateline, thread.views, thread.replycount, thread.visible, thread.open, thread.prefixid, forum.title AS forumtitle, user.username, user.userid, user.usergroupid, user.displaygroupid, user.avatarid, user2.avatarid AS avatarid2
" . iif($vbulletin->options['threadpreview'], ",post.pagetext AS preview") . "
" . iif($vbulletin->options['avatarenabled'], ',avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline') . "
" . iif($vbulletin->options['avatarenabled'], ',avatar2.avatarpath AS avatarpath2, NOT ISNULL(customavatar2.userid) AS hascustomavatar2, customavatar2.dateline AS avatardateline2') . "
FROM " . TABLE_PREFIX . "thread AS thread
LEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.username = thread.postusername)
LEFT JOIN " . TABLE_PREFIX . "user AS user2 ON (user2.username = thread.lastposter)
INNER JOIN " . TABLE_PREFIX . "forum AS forum ON (forum.forumid = thread.forumid)
" . iif($vbulletin->options['threadpreview'], "LEFT JOIN " . TABLE_PREFIX . "post AS post ON (post.postid = thread.firstpostid)") . "
" . iif($vbulletin->options['avatarenabled'], "LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON(avatar.avatarid = user.avatarid) LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON(customavatar.userid = user.userid)") . "
" . iif($vbulletin->options['avatarenabled'], "LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar2 ON(avatar2.avatarid = user2.avatarid) LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar2 ON(customavatar2.userid = user2.userid)") . "
WHERE NOT ISNULL(thread.threadid) AND thread.visible = '1' AND thread.open!='10' $forumfilter
ORDER BY rand(), lastpost DESC
LIMIT 0, {$vbulletin->options['rcmt_reclimit']}
");
I think this command
ORDER BY rand(), lastpost DESC
is the reason caused slow queries on my forum.
How to fix this?