[英]Creating history or log for certain events
I am not sure what is better perfomance whise so I ask you guys. 我不确定哪种性能更好,所以我问你们。
The problem is following: 问题如下:
I have a system where each User gets a certain amount of credit for certain events. 我有一个系统,其中每个用户为某些事件获得一定数量的信用。 So I gave my User an attribute named creditscore that gets altered on those events. 因此,我为用户提供了一个名为creditscore的属性,该属性在这些事件上发生了变化。 Everything works well. 一切正常。 But now I want the user to actually see what he did when and how much credit he got for this. 但是现在我希望用户实际看到他什么时候做了什么以及为此获得了多少信用。
What would be better here: 什么会更好:
Saving the whole history in a text attribute and add lines for each event 将整个历史记录保存在text属性中,并为每个事件添加行
or 要么
writing an extra model associated with the user and create an instance for every event. 编写与用户关联的额外模型,并为每个事件创建一个实例。 or 要么
or 要么
something way different? 有什么不同吗?
Since there are several events per user per day it would be either a huge text or a huge amount of instances. 由于每个用户每天有多个事件,因此可能是大量文本或大量实例。 What would be better looking at website performance. 看网站性能会更好。
You absolutely do NOT want to store the history in a text attribute. 您绝对不希望将历史记录存储在text属性中。 Management of this will be a nightmare as will querying the data. 与查询数据一样,对此的管理将是一场噩梦。
You could create a CreditEvent model and store the individual events in there. 您可以创建一个CreditEvent模型并在其中存储各个事件。 That would work fine. 那会很好。
However, before you start, check rubygems.org and ruby-toolbox.com to see if someone has already done the hard work. 但是,在开始之前,请检查rubygems.org和ruby-toolbox.com以查看是否有人已经完成了艰苦的工作。 I know of at least one gem that seems to do exactly what you want to do: 我知道至少有一种宝石似乎确实可以满足您的要求:
https://github.com/merit-gem/merit https://github.com/merit-gem/merit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.