哪种 MySQL 模式最适合此类系统

发布于 2024-09-19 01:55:22 字数 796 浏览 5 评论 0原文

假设有一个类似于 Netflix 的系统,其中成员创建了一个电影愿望清单,并根据他们的计划类型,将列表中的一部、两部或多部电影变成订单,那么以下哪一种模式更有意义?

  1. 存储以下列的控制表:

    controls(memberid, currentMoviesAtHome, movieAtHomeLimit, currentMonthlyMovies, MonthlyMoviesLimit)

用户实际上并不决定何时创建订单因为这取决于他们的帐户控制。日常功能将检查客户及其控件,并选择 currentMoviesAtHome currentMoviesAtHome currentMoviesAtHome currentMoviesAtHome currentMoviesAtHome currentMoviesAtHome currentMoviesAtHome movieAtHomeLimit 和当前每月电影 < MonthlyMoviesLimit ...

  1. 链接到plans计划表的单独accounts表:

    帐户(memberid、planid、currentMoviesAtHome、currentMonthlyMovies)

    plans(planid, movieAtHomeLimit, MonthlyMoviesLimit)

Assuming a system similar to Netflix where members create a wish list of movies and, based on their type of plan, one, two, or more of those movies in their list turn into orders, which one of the following schemas makes more sense?

  1. A controls table storing the following columns:

    controls(memberid, currentMoviesAtHome, moviesAtHomeLimit, currentMonthlyMovies, monthlyMoviesLimit)

The user does not actually decide when the order is created as that depends on their account controls. A daily function will go through the customers and their controls and choose ones where currentMoviesAtHome < moviesAtHomeLimit AND currentMonthlyMovies < monthlyMoviesLimit ...

  1. A separate accounts table linked to a plans plans table:

    accounts(memberid, planid, currentMoviesAtHome, currentMonthlyMovies)

    plans(planid, moviesAtHomeLimit, monthlyMoviesLimit)

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

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

发布评论

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

评论(2

薄凉少年不暖心 2024-09-26 01:55:22

第二个选项具有 ACCOUNTSPLANS 表,已标准化,因此这是我的建议。

此外,这些表:

  • MOVIES
  • WISHLIST
    • movie_id(主键,MOVIES.movi​​e_id 的外键)
    • account_id(主键,ACCOUNTS.account_id 的外键)
    • 在现场

is_onsite 将是一个布尔值确定电影是否已发送给客户端。如果有,值应设置为 1。使用该值求和即可了解帐户是否达到或低于其计划限额。返回视频时,仅删除 is_onsite 设置为 1 的行。

The second option, having the ACCOUNTS and PLANS tables, is normalized so it would be my recommendation.

Additionally, these tables:

  • MOVIES
  • WISHLIST
    • movie_id (primary key, foreign key to MOVIES.movie_id)
    • account_id (primary key, foreign key to ACCOUNTS.account_id)
    • is_onsite

The is_onsite would be a boolean to determine if the movie has been sent to the client. If it has, value should be set to 1. Use this to sum to know if the account is at or under their plan limit. When videos are returned, only delete the rows that have is_onsite set to 1.

独留℉清风醉 2024-09-26 01:55:22

日常功能将检查客户及其控制并选择

这并不能回答您的问题,但我想我会提到您的设计不是最佳的。正如您上面所描述的,您最好根据需要决定要做什么,而不是进行轮询;也就是说,在应用程序的使用过程中,显然会有一段时间限制值会被更新。您应该做的是当时触发某种事件并消耗该事件,以决定是否发送另一部电影。

每天的投票不会扩大规模。

触发和处理事件不仅会更快,而且从长远来看也更容易维护。祝你好运。

A daily function will go through the customers and their controls and choose

This doesn't answer your question but I thought I'd mention that your design is suboptimal. Rather than polling, as you describe above, you're much better off deciding what to do on-demand; that is, there will obviously be a time in your application's use where the limit values will be updated. What you should do is fire some kind of event at that time and consume the event that will decide whether or not to send out another movie.

Polling on a daily basis will not scale.

Firing and handling an event will not only be faster but it will be easier to maintain in the long run. Good luck.

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