I need some advice:
I am developing an rails application where multiple users click a button. I need to know how many times the button has been clicked and disable the button when the click amount reaches a certain number.
What is better?
- Including in the button table, a column called “clicks” and updating the number by 1 each time the button is clicked?
- Create a clicks table and insert a row every time the button is clicked then check the number of rows?
- Other suggestions would be great as well.
Edit
The button can be clicked an infinite number of times per user, and I need to know which user caused the button to disable.
My original thought was a table with 4 Columns:title goal user_id current_number
and just increment current_number by 1 each time and store the user id of the user that makes the number reach the goal.
Your first solution seems appropriate, the only downside I see is that once the clicked goal is reached your
current_numberfield becomes redundant but I don’t really see any way of getting around that without over-complicating your application.The only thing that I think you might be able to expand on is possibly incorporating some sort of background queuing system with a redis back-end such as Resque or Sidekiq. I would only look down this path if performance is a concern, however.
You can check out the recommendable repository on github for a similar implementation using background processing & redis.