数据存储困境 - 作为整数计数还是作为关联?

时间:2022-11-11 16:50:09

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:

我有一个Rails应用程序,鼓励用户点击网站周围的不同按钮。在存储数据时,我需要记录两件事:

1) The total number of people that have clicked each individual button. 2) The number of unique people that have clicked each individual button.

1)单击每个按钮的总人数。 2)单击每个按钮的唯一人数。

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.

95%的时间,我不需要知道实际进行点击的人是谁。非常频繁地访问此数据。另外5%的时间我需要知道谁点击了什么,我需要迭代这些人并执行某些操作。

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?

现在我有一个Click模型,记录用户和每次点击的按钮。我不确定的是我是否应该对点击进行某种独特的选择以找到唯一的点击,或者我是否应该为唯一点击创建单独的模型。此外,为按钮模型创建num_clicks列并在每次有人点击时增加它以及将点击添加为记录是否明智?或者我应该每次只做一个选择计数(*)?

Thanks for the help!

谢谢您的帮助!

1 个解决方案

#1


1  

You can use the counter cache columns for all your purposes.

您可以将计数器缓存列用于所有目的。

#1


1  

You can use the counter cache columns for all your purposes.

您可以将计数器缓存列用于所有目的。