Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m planning to add a couple of usage statistics to my web application. Some co

ID: 650768 • Letter: I

Question

I'm planning to add a couple of usage statistics to my web application. Some common things like: registered users, amount of comments/posts, etc. over time (last 24 hours / last week / last month / last year) which I want to display graphically to all admins.
I know that I can retrieve all information from database queries, but I have a bad feeling going over "old data" over and over again.

Example: Yesterday, I requested the amount of users who registered for an account the last year. Admin XYZ requests the same statistic today. A simple select-all-users-reg-date-last-year query would be redundant and cause much database traffic, right?

What is the best approach of calculating statistical data like this?

Explanation / Answer

You can get arbitrarily fancy with things like this, but it's probably not worth it. Unless you've observed that you're actually causing too much database traffic with the straightforward way, just do that and move on to something else. If you are, then for the query you've described, you could precompute each day's new users and then just sum one year worth of totals at query time. You can go further than that, even, but it's really not likely to be worthwhile.