V
V
veydlin2020-02-20 21:40:37
MySQL
veydlin, 2020-02-20 21:40:37

How to hide viewed posts?

There is a site with posts, or rather a feed with pictures, there should be an option to "hide viewed" forever

Very quickly, thousands, then hundreds of thousands of posts are typed for each user, how to exclude them from the selection without loading the server?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dimonchik, 2020-02-21
@dimonchik2013

visible = 0

N
nokimaro, 2020-02-21
@nokimaro

There is no magic bullet. If there is such a task, then only store lists of viewed posts for each user of the form user_id, post_id
And when building a feed, respectively, exclude from the selection what is "not necessary" either through JOIN or through a subquery of the form NOT IN (...)
In this In this case, good indexes and sufficient RAM per server should solve most performance problems.
Also, perhaps now we are talking about premature optimization, since will there really be hundreds of thousands of posts that a single user will view? After all, this is a colossal volume that someone else should post.
As an optimization option, for the future, you can clean up the history of "viewed posts" by deleting entries older than such and such a date or by number.
That is, store browsing history "for a month" or store the last 1000-10000 posts viewed by each user, which is not such a big number.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question