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

Reply
 
Thread Tools
Homepage Statistics Cache Details »»
Homepage Statistics Cache
Version: 1.00, by Tigga Tigga is offline
Developer Last Online: Nov 2023 Show Printable Version Email this Page

Version: 2.3.x Rating:
Released: 04-03-2003 Last Update: Never Installs: 31
 
No support by the author.

A little while ago I ran into this problem... I like having a lot of statistics on my forum's homepage, but I don't like having a lot of queries on that page. That got me to start thinking of a better way to do it, hence the creation of this hack.

How does this hack work?
It's pretty simple really. Instead of counting every single thread, post, member and etc every time someone loads your forum, it only counts these after a specified amount of time and updates one table that the information will be pulled from. This hack is especially useful for high traffic sites and can reduce the time it takes to load your forum's homepage.

Statistics Included:
Total Threads
Threads Today
Total Posts
Posts Today
Total Members
Newest Member
Top Poster
Top Thread Starter
If you are an admin, it will show you the last time the stats were updated as well.

(Please note that some of these started as hacks from other members at vB.org. Most of them are so simple though I don't see much of a point in trying to figure out which one's I got from here X months ago. If your hack was included here and you would like credit given please post here and I will add it.)

Normally these stats would add 8 queries to your forum's homepage. With this hack installed it will only perform 1 query most of the time, and 9 queries when it needs to update the information. I have found this very useful to cut down on the number of queries on my homepage, decrease the page's loading time, and put less overall stress on my server.

Well that's about it. I hope some others will find this hack useful and if anyone has some suggestions for other stats they would like to include in the stats cache please let me know and I will try to implement them.

Show Your Support

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

Comments
  #12  
Old 04-04-2003, 03:17 AM
Snapperhaed Snapperhaed is offline
 
Join Date: Mar 2003
Location: Argentina
Posts: 32
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Tigga, #3 can be found at:
https://vborg.vbsupport.ru/showthrea...threadid=25755

Thanks!! I'll also peep to see what I may have altered.
Reply With Quote
  #13  
Old 04-04-2003, 03:53 AM
Tigga's Avatar
Tigga Tigga is offline
 
Join Date: Dec 2001
Location: Atlanta
Posts: 1,061
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well here's the first two for you. The 3rd looks like it would take a little more work so I'll have to post that for you tomorrow.

For members today and total thread views, first run this query via phpMyAdmin:

ALTER TABLE `statscache` ADD `threadviews` INT( 10 ) UNSIGNED DEFAULT '0' NOT NULL ;
ALTER TABLE `statscache` ADD `memberstoday` INT( 10 ) UNSIGNED DEFAULT '0' NOT NULL ;

Then open your index.php file (assuming you've already installed the hack) and look for:
PHP Code:
$getstats[posttoday]=number_format($getstats['posttoday']); 
Below that Add:
PHP Code:
$getstats[threadviews]=number_format($getstats['threadviews']);
$getstats[memberstoday]=number_format($getstats['memberstoday']); 
Then look for:
PHP Code:
$poststoday=$getpoststoday[count]; 
Below that Add:
PHP Code:
// members today
$getmemstoday=$DB_site->query_first("SELECT count(*) AS count FROM user WHERE joindate>='$datecut'");

// thread views
$getthreadviews=$DB_site->query_first("SELECT SUM(views) AS tviews FROM thread"); 
Then look for:
PHP Code:
posttoday='$poststoday'lastupdate='".time()."'"); 
Replace that with:
PHP Code:
posttoday='$poststoday'lastupdate='".time()."'threadviews='$getthreadviews[tviews]',memberstoday='$getmemstoday[count]'"); 
Then just add the variables $getstats[threadviews] and $getstats[memberstoday] in your forumhome template where you would like those to appear. (Remember it will take 10 minutes, or however long you set between updates, before those will appear.)
Reply With Quote
  #14  
Old 04-04-2003, 04:01 AM
Snapperhaed Snapperhaed is offline
 
Join Date: Mar 2003
Location: Argentina
Posts: 32
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank You, Thank You, Thank You!!

Installed and worked perfectly. Many thanks for the assistance!
As a side note, I checked to make sure none of the original code was altered, before install, and it wasnt. But soon as I made the changes you provided, cured the problem right up!

Again, Thank you! Your the greatest.
Reply With Quote
  #15  
Old 04-04-2003, 04:41 AM
Logician's Avatar
Logician Logician is offline
 
Join Date: Nov 2001
Location: inside vb code
Posts: 4,449
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

caching such stats are always a good idea, especially in forum home, so very good job!
Reply With Quote
  #16  
Old 04-04-2003, 04:49 AM
Tigga's Avatar
Tigga Tigga is offline
 
Join Date: Dec 2001
Location: Atlanta
Posts: 1,061
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Snapperhaed - No problem at all. I've added those stats to my forum page as well.
By the way, I noticed that you have mYvBindex installed on your site. You can use the same code there to pull the info and save 4 queries on your homepage (and add more stats) as well.

Logician - Thank you.
Reply With Quote
  #17  
Old 04-04-2003, 06:21 AM
mossyuk mossyuk is offline
 
Join Date: Jul 2002
Posts: 35
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

1997 PMs?!?! Is that in total or just yours? Wow
Reply With Quote
  #18  
Old 04-04-2003, 11:33 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok, I got the other 2 figured out (finally). This is what I have left. Can anyone please tell me how to incorporate this, too?

Quote:
//Page Counter Code
$mycounter = $DB_site->query_first("SELECT count FROM mycounter");
$DB_site->query("UPDATE mycounter SET count = count + 1");
$mycounter = number_format($mycounter['count']);
//Page Counter Code
Reply With Quote
  #19  
Old 04-04-2003, 11:50 AM
Kars10's Avatar
Kars10 Kars10 is offline
 
Join Date: Jun 2002
Location: Germany/Franken
Posts: 748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Works like a charm and saves me about 5 Querys on Forumhome / and vBindex!!

Thanks
Kars

[high]* Kars10 kicks install! [/high]
Reply With Quote
  #20  
Old 04-04-2003, 04:23 PM
Tigga's Avatar
Tigga Tigga is offline
 
Join Date: Dec 2001
Location: Atlanta
Posts: 1,061
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

mossyuk - Yep, those are all mine. The board's been up for a little over a year and I rarely delete anything, so I guess they add up pretty quickly.

Boofo - I don't think that's something that should really be integrated with this... Since it's a page counter, updating it only every ten minutes wouldn't allow it to be accurate. It appears that it would only be 2 very small queries and a small table though, so it shouldn't affect performance much at all.

Kars10 - Glad you like it.
Reply With Quote
  #21  
Old 04-04-2003, 04:31 PM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You're right. I got to thinking about it after I wrote the message. I went from 31 queries down to 23 (and at 35 when the cache updates) and I have a couple of more stats than I had before. I did the Top Profile Views with this, too, if anyone is interested.
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 04:16 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05163 seconds
  • Memory Usage 2,325KB
  • 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
  • (6)bbcode_php
  • (1)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
  • (11)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