1

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!

Cristian Sanchez
  • 31,171
  • 11
  • 57
  • 63
Jake
  • 1,285
  • 11
  • 40
  • 119
  • 1
    how many total votes are you expecting in a day? If it amounts to hundreds per second, a single-server MySQL db might not cut it. (a physical file is out of the question if you want concurrency and reasonable storage space) –  Jul 27 '11 at 01:42
  • @bdares not sure exactly. But the userbase is around 400 members so I wouldn't imagine a whole ton. Thinking of limiting # of votes daily around 50-100 so we could limit the amount of interaction. – Jake Jul 27 '11 at 15:37

2 Answers2

4

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.

FiveTools
  • 5,970
  • 15
  • 62
  • 84
  • Brillaint! Thank you so much it sounds like you've had to do this before. Or are just very intelligent with program design. – Jake Jul 27 '11 at 15:36
0

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 -- i.e. 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.

Soren
  • 14,402
  • 4
  • 41
  • 67