简体   繁体   中英

How to Limit Amount of Votes a User can Give in 24 Hours?

I'm working to build a module in Pligg CMS which would limit a user to the amount of votes they can give in 24 hours. If they pass the limit (let's say 40/day) a JavaScript popup comes up to say "slow down!" ... similar to how Digg has updated their system.

What is the best way to keep track of the daily votes? Should I query the MySQL database every time a vote is cast to check if they're passing the limit? Or is it smarter to store the data in some type of physical file on the server? I don't really know how to build cache data so I'm thinking of creating a function to manually check the amount of votes each time. Would like to hear better suggestions of course!

Use your database and when saving - query the database for the number of votes cast in a specific time period, and if below your threshold, save. If over the threshold, pop back a javascript alert to inform the user of the problem.

You may want to get something scaleable like memcached or membase to keep track if the voloume is going to be large. If you use memcaced, you would want to implement it so that every vote will update a counter in memcached AND at the same time add a log entry which would roll up into a MySQL consolidated record. The nice thing of this, is that you will keep you MySQL as a master source, which can catche up at any speed -- ie it does not matter too much if it is several minuted behind in cacthing up. When you try to update the memcached copy and if you fidn that it is not in memcache you simply just fetch the count from MySQL and you would not have a 99.99% syncronised count wich would be sufficently good to iomplement the popup when the use reach 40 votes.

However if you only expect to get a few hundered votes per hour, then you may just want to use MySQL without any caching os scaling means.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM