简体   繁体   中英

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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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