Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 3.0 > vBulletin 3.0 Full Releases
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Remove 1 Database Query Per Page Details »»
Remove 1 Database Query Per Page
Version: 1.1, by Trigunflame Trigunflame is offline
Developer Last Online: Nov 2019 Show Printable Version Email this Page

Version: 3.0.7 Rating:
Released: 04-16-2005 Last Update: Never Installs: 18
 
No support by the author.

Remove 1 Database Query Per Page


Intro:
The idea is, lets remove 1 query from each page load, if the person is just refreshing the page. At first this may sound not important or just plain stupid, but on "larger" forums, cutting 1 query is always welcomed I know.

Description:
Basically all this does, is check the current Session Location from the DB against the current WOL path; the Session is already provided by vbulletin, so no extra query there.

All we do, is simply check the Location from the Database against the current WOL, if they don't match then the query is allowed to update the database; if they are the same - it is simply ignored.

Affects:
The only things this will do, is prevent the updating of the "lastactivity", and "location" if a person keeps refreshing the page, IMO that's not really a big deal, vbulletin takes care of deleting and remaking new sessions when they expire anyway. As long as your members are browsing around and such, their lastactivity, location will be updated as per usual.

Updates:
Version 1.1 - Scripts whosonline, misc are allowed to always update.
Version 1.0 - Release

Instructions:
1. [ open includes/sessions.php ]
2. [ go to about line 354, or look for $bypass = intval(SESSION_BYPASS); ]
3. [ replace this block of code ]

PHP Code:
    $DB_site->shutdown_query("
        UPDATE " 
TABLE_PREFIX "session
        SET useragent = '" 
addslashes(USER_AGENT) . "', lastactivity = " TIMENOW $location ", styleid = $styleidiif(VB_AREA !== 'Upgrade'", bypass = $bypass") . "
        ###REPLACE###
        WHERE sessionhash = '" 
addslashes($session['sessionhash']) . "'"
        
'sessionupdate'
); 
4. [ with this block of code]

PHP Code:
    /**
     * Update Location On Page Change
     *
     * @author Trigunflame
     * @version 1.1
     * @copyright Dusty Burns 2005-2006
     */

    // Check Script
    
if ($session['location'] != WOLPATH || THIS_SCRIPT == 'misc' || THIS_SCRIPT == 'online')
    {
        
$DB_site->shutdown_query("
            UPDATE " 
TABLE_PREFIX "session
            SET useragent = '" 
addslashes(USER_AGENT) . "', lastactivity = " TIMENOW $location ", styleid = $styleidiif(VB_AREA !== 'Upgrade'", bypass = $bypass") . "
             ###REPLACE###
             WHERE sessionhash = '" 
addslashes($session['sessionhash']) . "'"
            
'sessionupdate'
        
);
    }

    
/**
     * End Update Locations On Page Change
     */ 
5. [ save file ]

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #12  
Old 04-18-2005, 10:57 AM
Trigunflame's Avatar
Trigunflame Trigunflame is offline
 
Join Date: Aug 2002
Posts: 742
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by T3MEDIA
Hummm how are you guys checking your queries? via putty or something?
1. open index.php
2. go to bottom above eval('$navbar = "' . fetch_template('navbar') . '";');
3. put echo " ";
4. open includes/functions.php
5. find exec_shut_down()
6. at bottom, of function place echo "Queries: $query_count <br />";
7. there you go.

At the bottom the other queries hack is from erwin/teck, but like i said theirs doesn't count shutdown queries..

And without my small mod, the number to the right will show 9 everytime, instead of 8.
Reply With Quote
  #13  
Old 04-18-2005, 01:07 PM
Trigunflame's Avatar
Trigunflame Trigunflame is offline
 
Join Date: Aug 2002
Posts: 742
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Update;

Scripts whosonline and misc, are allowed to update page.
Reply With Quote
  #14  
Old 04-18-2005, 01:24 PM
buro9 buro9 is offline
 
Join Date: Feb 2002
Location: London, UK
Posts: 585
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you want to confirm when this query is being run, just add:
Code:
echo ".";
To the line above:
Code:
  	$DB_site->shutdown_query("
  		UPDATE " . TABLE_PREFIX . "session
Before you install this hack you'd see a dot in the top left hand corner of every page... but after you install this hack you'll only see the dot when you browse to new pages... click refresh on a page and the dot disappears.

Which means the query on the line after it disappears too.

This hack is pretty neat and will help to shave this unneeded query. If you have a large board 200+ users online the it's a good hack to install.

And no, it doesn't add queries anywhere

Whilst TrigunFlame is on a roll we should point him towards the index page to see if he can miraculously find some way of improving that too... I'm down to 0.06 seconds generate time... but I know it can be lower
Reply With Quote
  #15  
Old 04-18-2005, 01:55 PM
nexialys
Guest
 
Posts: n/a
Default

please edit this, a if else if is not really appropriate... just change the first one:
PHP Code:
    if (in_array(THIS_SCRIPT$badScripts) OR ($session['location'] != WOLPATH)) 
Reply With Quote
  #16  
Old 04-18-2005, 01:57 PM
Trigunflame's Avatar
Trigunflame Trigunflame is offline
 
Join Date: Aug 2002
Posts: 742
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by nexialys
please edit this, a if else if is not really appropriate... just change the first one:
PHP Code:
    if (in_array(THIS_SCRIPT$badScripts) OR ($session['location'] != WOLPATH)) 
how about this instead:

PHP Code:
if ($session['location'] != WOLPATH || THIS_SCRIPT == 'misc' || THIS_SCRIPT == 'online'
note: been up 3 days straight almost giving support and workin on stuff, give me a break :tired:
Reply With Quote
  #17  
Old 04-18-2005, 02:58 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

nevermind

just installed
Reply With Quote
  #18  
Old 04-18-2005, 03:05 PM
Deaths Deaths is offline
 
Join Date: Oct 2004
Location: Europe, Belgium
Posts: 679
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

http://www.vbulletin.com/docs/html/codestandards_and_or

You're using ||

Nice hack by the way, very usefull for big boards. /me installs
Reply With Quote
  #19  
Old 04-18-2005, 03:07 PM
buro9 buro9 is offline
 
Join Date: Feb 2002
Location: London, UK
Posts: 585
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Lord above, I never knew that file existed or that vBulletin had coding standards!

I now fear for my own hacks if standards police are going to come knocking
Reply With Quote
  #20  
Old 04-18-2005, 03:09 PM
Deaths Deaths is offline
 
Join Date: Oct 2004
Location: Europe, Belgium
Posts: 679
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hehe .

It's a very usefull file, nice to read through it when you are bored .

Many authors make this mistake, but I just happened to notice it while scrolling his code.
Reply With Quote
  #21  
Old 04-18-2005, 03:33 PM
Trigunflame's Avatar
Trigunflame Trigunflame is offline
 
Join Date: Aug 2002
Posts: 742
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Deaths
http://www.vbulletin.com/docs/html/codestandards_and_or

You're using ||

Nice hack by the way, very usefull for big boards. /me installs
Unfortunately you cannot depend on Vbulletin for coding standards, as its inards are a lot of crap coding.

I prefer using || instead of OR; They just suggest using it for readability, in PHP Documentation, it does not matter.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:52 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.07678 seconds
  • Memory Usage 2,332KB
  • Queries Executed 25 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (2)bbcode_code
  • (5)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)pagenav_pagelink
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete