So the idea is to cache these results. You may ask, what purpose could that possibly serve? Well lets put this into more perspective. Let's say you had 1000 users on your forum constantly (like neowin). When a user is visiting your forum, what are they doing 98% of the time? They're either looking at a forum or topic. When they look at a forum or topic (with feature on) it's hitting the sessions table for information. Many users go in and out of topics and posts, so each user may hit 10 different pages with the active users list per minute. If you have 1000 users doing this, you have 10,000 requests per minute. And that doesnt even include the php loops for each active users list. There may be 10 users in some forums/topics. PHP loops pretty fast, but it all adds up.
So how would you cut off those requests, and keep the feature? The answer is somewhat simple, but like all improvements has a draw-back. The idea is to use a cron job that either runs 1 time per minute or 1 time every other minute (user selectable). This cron job would parse through the sessions table and do two things:
#1) Go through the sessions table and pull out sessions where a user is either looking at a topic or forum.
#2) Load a snap shot of these results from the previous run.
#3) Take a snap-shot of the results from #1 and store it for the next run.
#4) Store an active users list (html) in the topic/forum as a cache, using results from #1.
#5) Go through results in #2 (snapshot) and clear the cache if, and only if, that forum or topic was NOT processed in #4. We do this because we want to clear old results where the topic or forum isnt even being looked at.
This way the sessions table is only being accessed 1 time per minute, as opposed to 10,000 times.
The draw-back, as I mentioned earlier is, the active users list is only accurate up to a minute (or every other minute. What ever you choose it to be). However, it gives you a good enough idea of what's going on instead of being totally blind. I did something similar on my forum with a "Forum Title (# Viewing)" and 99% of the time it's completly accurate.
You could also do the same thing with the Board Index list as well. Just store the list in a cache. If you had 1000 users online and each one accessed the board once, that means it would look 1000 times for each of the 1000 users (in php) (1000 * 1000 = 1,000,000 php loops) . If you cache it, it's loads the list (text) for each user once.
Comments Appreciated
