PDA

View Full Version : index.php duplicate SELECT hack


10-08-2000, 11:32 AM
I'm new hacker of vBulletin. So backup your index.php first:-)

(1) find:
$categorys=$DB_site->query("SELECT categoryid,title,displayorder FROM category WHERE displayorder<>0 ORDER BY displayorder");

under it add:
$forummoderators=$DB_site->query("SELECT user.username,forumid FROM forumpermission,user WHERE user.usergroupid=forumpermission.usergroupid AND canadminedit=1");
while ($moderator=$DB_site->fetch_array($forummoderators)) {
$forum_idx=$moderator[forumid];
$mod[$forum_idx][]=htmlspecialchars($moderator[username]);
}


(2)find:
$forummoderators=$DB_site->query("SELECT user.username,user.usergroupid FROM forumpermission,user WHERE user.usergroupid=forumpermission.usergroupid AND canadminedit=1 AND forumid=$forumid");
if ($moderator=$DB_site->fetch_array($forummoderators)) {
$moderators=htmlspecialchars($moderator[username]);

while ($moderator=$DB_site->fetch_array($forummoderators)) {
$moderators.=", ".htmlspecialchars($moderator[username]);
}
} else {
$moderators="?";
}

REPLACE with:
if ($mod[$forumid]){
$moderators=join(",",$mod[$forumid]);
}else{
$moderators="?";
}


I benchmark my board with ab -c 5 -n 30 (apache 1.32),Requests per second from 0.9x up to 5.12 ^_^

AGAIN please backup your index.php first,I'm not sure if it's bug free.

10-08-2000, 12:18 PM
What's it do?
:D

10-08-2000, 10:59 PM
it's a hack to speed the showforums section of index.php up.

in the original code,Select moderators from forumpermission ... where forumid=1,2,3... every forum.

I hack it by select all moderators once.

10-09-2000, 01:17 PM
Ah, yes, that clears up alot ;)

10-09-2000, 01:35 PM
If this works as advertised then it should actually speed up alot of forums as that query is a severe hit, especially if their is no indexes on the user table.