PDA

View Full Version : Modifying a welcome panel's code? Too many queries!


Megareus Rex
09-07-2011, 07:40 PM
For years I've been using this welcome panel hack: https://vborg.vbsupport.ru/showthread.php?t=105958

It was coded by a friend of mine (not for my site, however), and we've been using it since we opened, however I recently audited where my site's queries and realized that his adds a massive SEVEN (7) queries to forumhome.

Unfortunately, I'm not very adept with coding, and the author of the hack hasn't touched coding since he released the version in that link.

If anyone is willing to help, would it be possible to reduce the query amount? I would think several of those variables it calls for are already called for the normal "forum stats" panel that it just has you delete the html for. I would dearly love to continue using the welcome panel (and I'm sure he enjoys seeing it in sue himself), so abandoning it or switching to a different one isn't something I care to do if at all possible.

Should anyone be willing, the author would probably be fine with them re-releasing an optimized version of the hack. He'd give explicit permission first, of course.

Thanks in advance for any help offered!

Megareus Rex
09-09-2011, 04:26 AM
Oh right, this may be easier if I posted the code for it. Here it is:

// ################ Welcome Panel V1.1 - Made by SmasherMaster ################
// Checks if it is on the index, otherwise it'll error out
if (THIS_SCRIPT == "index")
{
// Require User Functions
require_once('./includes/functions_user.php');
// Cell 1 - Avatar
$vbulletin->userinfo['avatar']=fetch_avatar_url($vbulletin->userinfo['userid']);
if($vbulletin->userinfo['avatar']=="") {
$vbulletin->userinfo['avatar']="<a href='profile.php?{$session['sessionurl']}&do=editavatar'><img src='images/avatars/noavatar.gif' alt='Edit Your Avatar' border='0'></a>";
} else {
$vbulletin->userinfo['avatar']="<a href='profile.php?{$session['sessionurl']}&do=editavatar'><img src='{$vbulletin->userinfo['avatar'][0]}' alt='Edit Your Avatar' border='0'></a>";
}
// Cell 2 - Quick Forum Stats
$vbulletin->userinfo['newposts'] = $db->query_first("select count(*) as newposts from ".TABLE_PREFIX."post where dateline >= {$vbulletin->userinfo['lastvisit']} and visible = 1");
$vbulletin->userinfo['newposts'] = vb_number_format($vbulletin->userinfo['newposts']['newposts']);
$vbulletin->userinfo['newthreads'] = $db->query_first("select count(*) as newthreads from ".TABLE_PREFIX."thread where dateline and lastpost >= {$vbulletin->userinfo['lastvisit']} and visible = 1 and sticky in(0,1)");
$vbulletin->userinfo['newthreads'] = vb_number_format($vbulletin->userinfo['newthreads']['newthreads']);
$vbulletin->userinfo['members']=$db->query_first("select count(*) as all_users from ".TABLE_PREFIX."user");
$vbulletin->userinfo['posts']=$db->query_first("select count(*) as all_posts from ".TABLE_PREFIX."post");
$vbulletin->userinfo['topics']=$db->query_first("select count(*) as all_topics from ".TABLE_PREFIX."thread");
$vbulletin->userinfo['yourposts'] = $db->query_first("select posts as your_posts from ".TABLE_PREFIX."user where userid = {$vbulletin->userinfo['userid']}");
$vbulletin->userinfo['yourposts'] = vb_number_format($vbulletin->userinfo['yourposts']['your_posts']);
$vbulletin->userinfo['postpercent'] = vb_number_format(((str_replace(',', '', $vbulletin->userinfo['yourposts']['your_posts']) / $vbulletin->userinfo['posts']['all_posts'] ) * 100),2);
$welcome_members="{$vbulletin->userinfo['members']['all_users']}";
$welcome_topics="{$vbulletin->userinfo['topics']['all_topics']}";
$welcome_posts="{$vbulletin->userinfo['posts']['all_posts']}";
$welcome_pms="<if condition='$show[pmstats]'><br /><phrase 1='$vbphrase[unread_x_nav_compiled]' 2='$vbphrase[total_x_nav_compiled]' 3='$session[sessionurl]'>$vbphrase[private_messages_nav]</phrase></if>";
$welcome_newposts="<a href='search.php?{$session['sessionurl']}&do=getnew'>New Posts</a>: {$vbulletin->userinfo['newposts']}<br>New Threads: {$vbulletin->userinfo['newthreads']}";
$welcome_time="<phrase 1='$vbphrase[last_visited_x_at_y]'>";
$welcome_avatar="{$vbulletin->userinfo['avatar']}";
}

BirdOPrey5
09-09-2011, 03:07 PM
7 queries on only the index page is no big deal. VB4 has some pages with 60+ queries. This really shouldn't be an issue.

Megareus Rex
09-10-2011, 01:49 AM
7 queries on only the index page is no big deal. VB4 has some pages with 60+ queries. This really shouldn't be an issue.

Well, maybe not, but if anyone's able to help optimize it more than it is, I'd certainly appreciate it.

BirdOPrey5
09-10-2011, 12:28 PM
What version of vBulletin are you running? After looking at it there seems to be a lot of queries for data that should already be available without the need for a query, at least in 3.7/3.8- I'm not sure about earlier versions.

BirdOPrey5
09-10-2011, 03:43 PM
After experimenting if the hook for that plugin is moved from forumhome_start to forumhome_complete almost all the queries can be eliminated... however the original author (maybe because it was made for VB 3.5) overwrites valid fields of userinfo with his data so it's not just a simple edit of the plugin- but edits of the template that will be needed as well. Virtually rewriting all the PHP portion of the mod.

I will contact the original author and see if he will give permission for a release, like you suspect.