This one should be pretty easy for an experienced programmer to answer.
I’ve got a Rails App where users are encouraged to click different buttons that are featured all around the site. When it comes to storing the data, I need to record two things:
1) The total number of people that have clicked each individual button.
2) The number of unique people that have clicked each individual button.
95% percent of the time, I don’t need to know WHO the people that actually did the clicking are. This data is accessed very frequently. The other 5% of the time I DO need to know who clicked what, and I need to iterate over those people and perform certain actions.
Right now I have a Click model that records the user and the button for each click. What I’m not sure about is whether I should be doing some sort of unique select on the clicks to find the unique ones, or if I should create a separate model for unique clicks. Furthermore, would it be smart to create a num_clicks column for the button model and increment it each time someone clicks as well as adding the click as a record? Or should I just do a select count(*) each time?
Thanks for the help!
You can use the counter cache columns for all your purposes.