实施排名系统

发布于 2024-07-25 21:11:53 字数 423 浏览 5 评论 0原文

我见过几个关于如何保护和防止滥用排名系统(例如盯着电影、产品等)的问题,但没有实际实施它。 为了简化这个问题,安全性不是我关心的问题,访问该系统的人都是受信任的,并且如果发生滥用排名系统的情况,那是微不足道的,并且比原因更容易恢复。 无论如何,我很好奇如何存储选票。

一种想法是建立一个投票表,记录每次投票,然后立即、在预定时间或在每次加载产品时(这似乎效率低下,但也许不是),对投票进行统计,并在 0 到 5 之间进行双倍计算。更新为产品表中的产品条目。

或者,我在产品表中存储总分和投票数,并在显示时将其除以,并在有人投票时将投票添加到总分和增量中。

还是有我没有想到的更好的方法? 我有点想在产品表中只有一个“评级”字段,但无法想出一种在没有一些附加数据的情况下更新投票的方法。

同样,数据完整性很重要,但绝不是必要的,有什么想法吗?

I've seen several question on how to secure and prevent abuse of ranking systems (like staring movies, products, etc) but nothing on actually implementing it. To simplify this question, security is not a concern to me, the people accessing this system are all trusted, and abuse of the ranking system if it were to happen is trivial and easier to revert than cause. Anyways, I'm curious how to store the votes.

One thought is to have a votes table, that logs each vote, and then either immediately, at scheduled times, or on every load of the product (this seems inefficient, but maybe not) the votes are tallied and a double between 0 and 5 is updated into the product's entry in the product table.

Alternatively, I store in the products table a total score and a number of votes, and just divide that out when I display, and add the vote to total and increment number when someone votes.

Or is there a better way to do it that I haven't though of? I'd kind of like to just have a 'rating' field in the product table, but can't think of a way to update votes without some additional data.

Again, data integrity is important, but by no means necessary, any thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

七秒鱼° 2024-08-01 21:11:53

我会为你的产品保留一个“分数”,但也会保留一个投票表,看看谁投票给了什么。 当有人投票时,插入投票,更新产品分数。

这允许快速排序,并且您还有一个表格可以重新计算分数并阻止人们重复投票。

无需等待写投票和更新分数。 这会带来问题,并且如果它像传统系统一样运行(读取多于写入),则不会给您带来任何好处。

I would keep a "score" with your products but would also keep a vote table to see who voted for what. And when somebody votes, Insert vote, update product score.

This allows quick sorting and you also have a table to be able to recalculate the scores from and to stop people double-voting.

There is no need to wait to write the vote and update the scores. That will introduce problems and if it's acting like a traditional system (lots more reads than writes), gives you no benefits.

冰魂雪魄 2024-08-01 21:11:53

您的意思是,您将把投票单独存储在一个表中,然后使用定义的策略更新产品表中产品的相应排名?
这似乎是一种低效的存储方式。 也许这个原因是有背景的; 但为什么您不想将所有投票存储在一张表中并继续将这些投票引用到相应的产品。 这将为您提供实时计数。

在用户界面上,您将计算所有投票的平均值以接近整数来显示。 这样就足够了,不是吗? 或者我错过了什么?

you mean, you'll store the votes seperately in a table and then update the respective ranking of product in product's table with a defined strategy?
That seems like an inefficient way of storing it. Maybe there is a background to that reason; but why would you not want to store all votes in one table and keep making references of those votes to respective product. This gives you a real time count.

On UI you'll calculate a average of all the votings to a near integer to show. That would suffice, isn't it? Or am I missing something?

暖伴 2024-08-01 21:11:53

我同意奥利的观点。 此外,您可以缓存您的分数。 因此,您更新缓存中的产品分数,并且您的应用程序始终会获取缓存值。 因此,即使刷新页面,您也可以获得最新分数,而无需访问数据库。

I agree with Oli. In addition, you can cache your score. So you update the product score in the cache and your application always picks up the cache value. Thus even on a page refresh, you would get the latest score without hitting the database.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文