用于星级评定的最佳 MySQL 数据库设置

发布于 2024-12-18 17:53:44 字数 438 浏览 1 评论 0原文

我有两张桌子。

表 A:包含歌曲列表、歌曲作品、mp3 链接、标签等。

表 B:包含注册用户信息、用户 ID、用户名等。

我即将向歌曲添加星级评级系统,并希望让任何人注册用户每首歌曲投票一次。

所以我最初的计划是创建第三个表并使用 JOIN:

表 C:包含 SongID、总分(所有投票的总和)、vote_count(投票数)并在 jQuery 中执行计算客户端以返回平均投票。

我认为这对于性能来说是最佳的,因为我将处理非常大的数据集。

当然,使用这种方法我无法防止用户随意投票。

因此,我的问题是,设置什么数据库最能防止作弊(即存储和检查表 C 中选民的用户 ID),而不会降低歌曲本身过滤/排序的性能,因为这是该项目的关键。

我希望我清楚地表达了这个要求,如果没有,我很抱歉。

I have two tables.

Table A: Contains a list of songs, song artwork, mp3 link, tags etc.

Table B: Contains registered user info, user id, username etc.

I am about to add a star rating system to the songs and would like to let any registered user vote only once per song.

So my plan initially was to create a third table and use a JOIN:

Table C: Containing songID, Total score(the sum of all votes cast), vote_count (number of votes) and perform a calculation clientside in jQuery to return the average vote.

I figured this would be optimal for performance since I will be dealing with extremely large datasets.

Of course using this method I would have no protection against users voting as many times as they want.

Therefore, my question is, what database set up would be best to protect against cheating (i.e. storing and checking against userID's of voters in table C) without degrading the performance of filtering/sorting the songs themselves as this is key to the project.

I hope I made this request clear, my apologies if not.

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

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

发布评论

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

评论(4

没有伤那来痛 2024-12-25 17:53:44

制作一个投票表:([userID,songID],评分)

也许在songID上放置一个索引以加快访问速度。

Make a vote table: ([userID, songID], rating)

Maybe put an index on songID for faster access.

又怨 2024-12-25 17:53:44

您的第三个表的结构应如下所示:

Song ID
User ID
Star Rating

- 在(歌曲 ID、用户 ID)上有唯一索引。 (您必须将歌曲 ID 和用户 ID 存储在一起才能知道谁投票了 - 没有办法解决这个问题。)

要返回给定歌曲的平均评分,只需

select AVG(`Star Rating`) From `Rating Table` where `Song ID` = ?

在索引表上,选择特定歌曲的平均值评分低于 1000 的歌曲应提供合理的访问时间。

Your third table should be structured like:

Song ID
User ID
Star Rating

- with a unique index on (Song ID, User ID). (You have to store Song ID and User ID together to be able to tell who has voted - there is no way around this.)

To return an average rating for a given Song, simply

select AVG(`Star Rating`) From `Rating Table` where `Song ID` = ?

On an indexed table, selecting an average for a specific Song with under 1000 ratings should give reasonable access times.

甜妞爱困 2024-12-25 17:53:44

试试这个:

  • 相册|艺术家 ID、艺术品
  • 艺术家 |总体评分
  • 歌曲 |艺术家 ID、专辑、评级
  • 用户

这样您就可以按艺术家、歌曲、专辑等进行拉取。

Try this:

  • Album | artist id, artwork
  • Artist | overall rating
  • Song | artist id, album, rating
  • Users

That way you can pull up by artist, by song, by album etc.

逆流 2024-12-25 17:53:44

取决于您希望评级的最新程度,对于星级评级,它不一定需要最新。因此,您可以

vote table: ([userID, songID], rating)

按照 Tom van der Woerdt 的建议进行操作,但您也可以为每首歌曲添加星级,并在有能力的情况下每天或每隔几个小时重新计算一次。

depends on how up to date you want the rating to be, for star rating, it doesn't necessarily need to right up to the minute. So you can have the

vote table: ([userID, songID], rating)

as Tom van der Woerdt suggested, but you can also add a star rating to each song and recalculate it daily or every few hours if you have the capacity.

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