结构数据的最佳方法仅显示用户未见记录

发布于 2025-01-22 10:31:10 字数 207 浏览 0 评论 0原文

假设您有一系列视频,您想跟踪用户看过这些视频的内容,并确保用户不会再次看到这些视频,或者最少会优先考虑用户在上面看过的视频。做这件事的最佳方法是什么?

在SQL中,我通常会使用左联接来完成此操作,并从消除用户看到的视频开始,但即使这也可能开始下降的性能。我知道我应该能够通过创建两个集合来做到这一点。一个用于视频,一个用于视图并使用查找,但我不确定是否有更好/更性能的方法来完成此任务。

Say you have a collection of videos and you would like to track what users has seen those videos and make certain that the users do not see those videos again or at bare minimum prioritize videos that a user hasn't seen above those that they have seen. What would be the best way to accomplish this that would scale?

In SQL I would typically use a left join to accomplish this and start by eliminating videos that the user has seen, but even this could start to decline in performance. I know that I should be able to do this by creating two collections. One for the videos and one for the views and use a lookup, but I wasn't sure if there was a better/more performant way to accomplish this task.

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

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

发布评论

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

评论(1

汹涌人海 2025-01-29 10:31:10

通常,您应该将有关视图的数据存储在与电影同一集合中:

const movies = [{
  id: 123,
  title: "Titanic",
  usersViewed: [1001, 1002]
}]

您可以在userviewed字段上简单地创建(Multikey)索引,以轻松过滤用户值。

如果Userviewed列表开始增长,并且您不需要常规电影查询的数据,则可以将其存储在单独的集合中。电影的常规查询将更快,但是要根据视图进行过滤,您需要执行额外的$ lookup用户ID索引将再次有所帮助。

const usersViewed = [{
  movieId: 123,
  userId: 1001 
}, {
  movieId: 123,
  userId: 1002
}]

Generally, you should store data about views in the same collection as movies:

const movies = [{
  id: 123,
  title: "Titanic",
  usersViewed: [1001, 1002]
}]

You can simply create (multikey) index on userViewed field to easily filter user values.

If the userViewed list starts growing, and you don't need the data for regular movies querying, you can store it in separate collection. Regular queries on movies would be faster, but for filtering based on views you would need to do extra $lookup. Index on userId will help again.

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