vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Modification Requests/Questions (Unpaid) (https://vborg.vbsupport.ru/forumdisplay.php?f=112)
-   -   Modifying a welcome panel's code? Too many queries! (https://vborg.vbsupport.ru/showthread.php?t=269842)

Megareus Rex 09-07-2011 06:40 PM

Modifying a welcome panel's code? Too many queries!
 
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 03:26 AM

Oh right, this may be easier if I posted the code for it. Here it is:

PHP Code:

// ################ 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 02: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 12:49 AM

Quote:

Originally Posted by BirdOPrey5 (Post 2243952)
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 11:28 AM

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 02: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.


All times are GMT. The time now is 06:31 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02969 seconds
  • Memory Usage 1,758KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete