开发者

How to retrieve the best voted article, per day, per week, per month or forever?

I've a voting system which is actually simple.

vote_id, user_id, article_id

I need now to be able to fetch the best voted article per day, week, month, year, forever.

I though I could add a DATETIME column and then use mysql function to retrieve vote BETWEEN or something and use DATE INTERVAL and other DATE OPERATIONS.

I also think I could denormalize and store "day of the year", "week of the year", "month of the year", "year", in columns for performance, I'll be able to fetch easily votes for one given day, or month.

Also, I'm wondering if I need to do it from a calendar point of view, it means "per month" may not be from "1 to 31" but from "12 to 12" crossing a two monthes.

Any ideas/feedbacks开发者_如何学JAVA?


If the smallest unit to present data is a day then I would start with a DATE column and SQL queries to determine the number of votes per time interval.

If it doesn't perform well enough with your amount of data you can optimize. Instead of adding columns you could also have a different table structure, to store the totals per period. Then the calculation would be performed on the inserts and no on every select.

About the calendar months, that depends on what the requirements of the system are.

Whatever option you use, be sure to consider effects of different timezones of the user and server!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜