简体   繁体   English

在sql db中存储已读文章的最佳方法是什么?

[英]What's the best way to store read articles in sql db?

I'm developing website that allows users to read articles. 我正在开发允许用户阅读文章的网站。 I want to implement functionality that offers to automatically mark articles read when they are accessed by a user. 我想实现一种功能,该功能可以在用户访问文章时自动将其标记为已读。 The problem is that I don't know how to store read article data in db. 问题是我不知道如何将读取的文章数据存储在db中。 There could be hundreds of thousands of articles and multiple thousands of users. 可能有成千上万的文章和成千上万的用户。 Storing row for each article/user in 'read articles' join table seems to be inefficient way. 在“已读文章”联接表中为每个文章/用户存储行似乎是一种低效的方式。 What are other options? 还有哪些其他选择?

There could be hundreds of thousands of articles and multiple thousands of users. 可能有成千上万的文章和成千上万的用户。 Storing row for each article/user in 'read articles' join table seems to be inefficient way. 在“已读文章”联接表中为每个文章/用户存储行似乎是一种低效的方式。

The scheme that stores one row per {user, article} pair is correct. 每对{user, article}对存储一行的方案是正确的。 The implication that having lots of rows makes this scheme inefficient is incorrect: modern databases are optimized to handle lots of rows very efficiently. 大量行使该方案效率低下的含意是不正确的:现代数据库经过优化,可以非常有效地处理大量行。

Moreover, the implication that having "hundreds of thousands of articles and multiple thousands of users" would translate into lots of rows is incorrect as well: you will be storing a row per article a user reads, not for every article, so the number of rows that you get would be orders of magnitude short of the worst-case estimate. 此外,“成千上万的文章和成千上万的用户”会转换成很多行的含义也是不正确的:您将为用户阅读的每篇文章而不是每篇文章存储一行,因此,您得到的行将比最坏情况的估计值短几个数量级。

Depending on your strategy: 根据您的策略:

If you store articles unique for each user (read me later functionality) you can store status with article. 如果您为每个用户存储唯一的文章(请向我阅读稍后的功能),则可以将状态与文章一起存储。

If you have set of articles which can be read by any of user, then you do it correctly introducing additional table to store read statuses. 如果您拥有一组可以被任何用户阅读的文章,那么您可以正确地引入其他表格来存储阅读状态。 I do not see anything wrong in this approach. 我看不到这种方法有什么问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM