Version: 1.00, by NTLDR (Coder)
Developer Last Online: Oct 2004
Version: 3.0.0
Rating:
Released: 01-20-2004
Last Update: Never
Installs: 170
No support by the author.
Latest Threads On Forum Home Version: 1.0.2 vB-version: 3.0.0 Release Candidate 2 Developer: NTLDR Install-difficulty: 1 File-edits: 2 Template-edits: 1
Description of the Hack:
This is taken from my vBindex hack and will display the latest X threads on your forum home page. Permissions are done automatically so forums users can't view will be excluded. Includes thread icon/goto new post image (if the thread is unread), title, last post info, number of views and replies.
Files modified for this Hack:
index.php
New templates for this Hack:
forumhome_latestthreadbit
Templates modified for this Hack:
FORUMHOME
New phrases for this Hack:
latest_threads
Show Your Support
This modification may not be copied, reproduced or published elsewhere without author's permission.
Hi Lee,
I looked at your code and I think there is a problem with your hack.
You are doing full table scans and that could easily crash your server in a busy site.
Your search for latest threads should generate at least a 70% MySQL activity...
IMO is extremly high. Let me know what you think.
Regards,
Floren.
Hm doesn't sound good, interested in what he has to say...
// [START HACK='Latest Threads On Forum Home' AUTHOR='NTLDR' VERSION='1.0.0' CHANGEID= 2 ]
// #################### PROCESS LATEST THREADS #######################
// fetch the permissions for each forum
$forumperms = array();
foreach($forumcache AS $forum) {
// ## HIDE FORUMS WITHOUT THE CANVIEW OR CANVIEWOTHERS PERMISSION ##
if (!($forumperms["$forum[forumid]"] & CANVIEW) || !($forumperms["$forum[forumid]"] & CANVIEWOTHERS)) {
$limitfids .= ','.$forum['forumid'];
}
}
unset($forum);
if ($vboptions['threadpreview'] > 0) {
$previewfield = ', post.pagetext AS preview';
$previewjoin = 'LEFT JOIN '.TABLE_PREFIX.'post AS post ON(post.postid = thread.firstpostid)';
}
$getthreads = $DB_site->query("
## GET LATEST THREADS ##
SELECT thread.*,thread.iconid AS threadiconid $previewfield FROM ".TABLE_PREFIX."thread AS thread
LEFT JOIN ".TABLE_PREFIX."deletionlog AS deletionlog ON(thread.threadid = deletionlog.primaryid AND type = 'thread')
$previewjoin WHERE open = '1'
AND forumid NOT IN (0$limitfids)
AND thread.visible = '1'
AND deletionlog.primaryid IS NULL
ORDER BY lastpost
DESC LIMIT 5");
eval("\$threadbits .= \"".fetch_template('forumhome_latestthreadbit')."\";");
}
if ($threads) {
$show['latestthreads'] = true;
}
// memory saving
unset($thread, $threads);
$DB_site->free_result($getthreads);
// [END HACK='Latest Threads On Forum Home' AUTHOR='NTLDR' VERSION='1.0.0' CHANGEID= 2 ]
With: (Changing X to the usergroupid you wish to show it for
PHP Code:
if (is_member_of($bbuserinfo, X) {
// [START HACK='Latest Threads On Forum Home' AUTHOR='NTLDR' VERSION='1.0.0' CHANGEID= 2 ]
// #################### PROCESS LATEST THREADS #######################
// fetch the permissions for each forum
$forumperms = array();
foreach($forumcache AS $forum) {
// ## HIDE FORUMS WITHOUT THE CANVIEW OR CANVIEWOTHERS PERMISSION ##
if (!($forumperms["$forum[forumid]"] & CANVIEW) || !($forumperms["$forum[forumid]"] & CANVIEWOTHERS)) {
$limitfids .= ','.$forum['forumid'];
}
}
unset($forum);
if ($vboptions['threadpreview'] > 0) {
$previewfield = ', post.pagetext AS preview';
$previewjoin = 'LEFT JOIN '.TABLE_PREFIX.'post AS post ON(post.postid = thread.firstpostid)';
}
$getthreads = $DB_site->query("
## GET LATEST THREADS ##
SELECT thread.*,thread.iconid AS threadiconid $previewfield FROM ".TABLE_PREFIX."thread AS thread
LEFT JOIN ".TABLE_PREFIX."deletionlog AS deletionlog ON(thread.threadid = deletionlog.primaryid AND type = 'thread')
$previewjoin WHERE open = '1'
AND forumid NOT IN (0$limitfids)
AND thread.visible = '1'
AND deletionlog.primaryid IS NULL
ORDER BY lastpost
DESC LIMIT 5");
I've had no problems running this code on several sites, though I may look into optimising it if and when I have time.
Lee, I hope you did not take it in a bad way my reflection, I was simply trying to help.
If you allow me, I will explain what is wrong with the code.
The query will perform a full scan from ALL forums and ALL threads. At this precise moment, the MySQL % will raise to the sky... for an instance the server will be suffocated with the flood of information it has to compile, in order to display the results, and that?s only for one person... imagine what will happen when 500 users will visit in the same time your front page.
A good rule to keep in mind for coders is: never perform full table scans.
If you have a very small forum with 200-300 posts, that will not really count, since your database is very small, but what do you do with huge forums who have 1 million posts?
Unfortunatelly, the 5 threads limit does not reduce the query scan at all, it will perform it, then grab only the latest 5 results.
What I recommend you to do is this: put a time/date limit in the query. In this way, instead of scanning the hole forum/thread tables, you select a very small portion of it.
The result is obvious, a very small database/server usage...
With: (Changing X to the usergroupid you wish to show it for
PHP Code:
if (is_member_of($bbuserinfo, X) {
// [START HACK='Latest Threads On Forum Home' AUTHOR='NTLDR' VERSION='1.0.0' CHANGEID= 2 ]
// #################### PROCESS LATEST THREADS #######################
// fetch the permissions for each forum
$forumperms = array();
foreach($forumcache AS $forum) {
// ## HIDE FORUMS WITHOUT THE CANVIEW OR CANVIEWOTHERS PERMISSION ##
if (!($forumperms["$forum[forumid]"] & CANVIEW) || !($forumperms["$forum[forumid]"] & CANVIEWOTHERS)) {
$limitfids .= ','.$forum['forumid'];
}
}
unset($forum);
if ($vboptions['threadpreview'] > 0) {
$previewfield = ', post.pagetext AS preview';
$previewjoin = 'LEFT JOIN '.TABLE_PREFIX.'post AS post ON(post.postid = thread.firstpostid)';
}
$getthreads = $DB_site->query("
## GET LATEST THREADS ##
SELECT thread.*,thread.iconid AS threadiconid $previewfield FROM ".TABLE_PREFIX."thread AS thread
LEFT JOIN ".TABLE_PREFIX."deletionlog AS deletionlog ON(thread.threadid = deletionlog.primaryid AND type = 'thread')
$previewjoin WHERE open = '1'
AND forumid NOT IN (0$limitfids)
AND thread.visible = '1'
AND deletionlog.primaryid IS NULL
ORDER BY lastpost
DESC LIMIT 5");