![]() |
Homepage Statistics Cache
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. |
There's not much to it, but here's a screen shot as well. :)
|
looks nice, ill try this out ty
|
this also makes my last post on forum home hack update every ten mins along with the rest of the stuff you included above.
Is there anyway I can change this? |
clicksm install
|
nevermind.. my fault
It saves 8 queries per load for me |
How can we also cache the moderatorlist ?
XENON has a hack for this.. but it isn't compatable with this hack https://vborg.vbsupport.ru/showthrea...=&pagenumber=1 |
Thanks for pointing that out SgSling. I had forgotten about his modifications (I have Xenon's hack installed too). He saves another query by counting the posts in the thread query, so to use that with this hack you would just replace this (in the hack itself, or index page if you've already modified it):
PHP Code:
PHP Code:
|
Lets say I wanted to add a few more items to be cached ...
1 - Total Thread Views 2 - New Members Today 3 - Most popular thread by # of Replies These 3 items I have installed, but they dont show now since I added this hack. (A nice one might I add). I know (or i think rather) I need to add them into the table via a query, then adjust accordingly on the forumhome template ... But since im new to it, (i already ran the intial query), how can I add to the exist newly created table? (IE: add this to the statscache table) ... Any/All help appreciated!! |
Snapperhaed - The first 2 wouldn't be hard to add at all. If you'll give me a link to the 3rd one you're talking about I'll have a look at it to see what would need to be done to add it as well. :)
Oh, and those things should still work fine without the stats cache as long as you didn't modify any of the code that was for those hacks... |
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. :D |
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:
PHP Code:
PHP Code:
PHP Code:
PHP Code:
PHP Code:
|
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. :p |
caching such stats are always a good idea, especially in forum home, so very good job! :)
|
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. :D |
1997 PMs?!?! Is that in total or just yours? Wow :)
|
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:
|
Works like a charm and saves me about 5 Querys on Forumhome / and vBindex!!
Thanks Kars [high]* Kars10 kicks install! :)[/high] |
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. :) |
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. ;)
|
did u update the attachment with the add-ons?
|
great hack, saves me 7 queries nice
|
Very nice hack, man. Here's updated instrucs with the add-ons.
|
Awesome idea Tigga :)!
- miSt |
Quote:
[high]* Prankster too [/high] great idea thanks greets Prankster |
OK, what should we do if we have some or all of the old hacks your new hack is based on so we can truly save queries instead of adding 9 new to the 8 old ones? ;)
|
If you have all (or some) of these stats installed already, you would pretty much just replace the coding for those stats with the new code for the stats cache. It shouldn't be too hard to figure out what to replace, but if you have problems with it let me know.
|
Database error in vBulletin 2.3.0:
Invalid SQL: UPDATE statscache SET members='1617',threads='2145',posts='39246',topthr ead='Mijae',topthreadid='1',to pthreadnumber='186',topposter='Jim',topposterid='1 53',toppostnumber='2496',newes tmember='umar'newestmemberid='1617',threadtoday='0 ',posttoday='7',lastupdate='10 50682471', threadviews='259042',memberstoday='2' mysql error: You have an error in your SQL syntax near 'newestmemberid='1617',threadtoday='0',posttoday=' 7',lastupdate='1050682471', thr' at line 1 mysql error number: 1064 |
It looks like a comma is somehow missing in that query. Make sure you have a comma right before 'newestmemberid' in the query that updates the cache.
|
Up and running in v2.2.0!!!
|
Btw,
- how do i change ',' char to '.' char (eg.: 325,500,934 to read 325.500.934) - how do i know how many queries currently my homepage loads? Ideas? |
DO NOT cache the SINCE YOUR LAST VISIT! hack by MrLister (https://vborg.vbsupport.ru/showthrea...threadid=31957). Those of you who installed the WELCOME HACK [FINAL] are also affected, like me!
:P |
Areku - If you'll refer to a post I made here, that should help you. It's for a different hack, but it should be enough to help you figure out how to change the commas to periods. ;)
As for figuring out how many queries a page has, I would recommend installing Teck's Microstats hack. Alternatly you could open your admin/config.php file and put the code $debug="1"; right at the end of that file before the ?>. Then you would go to the url http://yoursite.com/forum/index.php?explain=1. At the bottom of that page it will show you the number of queries and the time it took to execute them. |
Does any1 know what's wrong with the SINCEYOURLASTVISIT addon I published 2 posts ago (https://vborg.vbsupport.ru/showthrea...005#post386005)?
Yesterday was working fine but today it displays Han habido 5,770 hilos y 33,486 mensajes desde tu ?ltima visita! that is, 33 thousand messages since my last visit, 30 seconds ago!!!! Wth is going wrong?? |
Yea, actually I just realized what you did with the new posts since a users last visit. You should not have done that... Every time it updates the cache, it will display the number of new posts for that particular user, so all users will see the same number of new posts and threads. There's really not a way to cache those since they are specific for each member.
|
Damn, I really messed it up! :P
OK I'll edit the previous post. Can you now explain me when does the update happen actually? It's 0:01am here (server time) and update has been done for this new day, but it's still counting/displaying yesterday's new members/posts/threads... |
Well actually it should go by the time that is set on the server to determine when a new day starts. Then it should update that table every 10 minutes (assuming you didn't change the value), so within 10 minutes it *should* be correct. I'll work on changing it so that it will go by your forums timeoffset values as well though since that would make a little more sense.
|
Quote:
PHP Code:
PHP Code:
|
Bofo - Actually the only thing that would affect is where it shows an admin the last time the cache was updated. The $datecut variable is what would need to be modified. ;)
|
I later realized you're right... server is on PST and I'm on GMT so it used server's time to update, presenting us "today registered users" when that was not true for our time zone ;)
Will wait for your fix then ;) |
All times are GMT. The time now is 06:55 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|