Answer the question
In order to leave comments, you need to log in
How to organize the feed of posts?
Hello, I really need your advice in terms of the proper organization of the database / storage for the feed of posts. The bottom line is this: you need to display all likened articles, everyone you subscribe to, but you need to group them so that the position of the article depends on the first like .... Now I’ll try to show this with an example.
We have users A,B,C. A follows B and C. Let users B and C like the same article. (First B then C). So in the feed, the position of this article should be by the first like, that is, by the time of like B.
First, two tables were made in MySQL:
SELECT min(id) as id, idPost, posts_likes.idUser
FROM `post_likes`,`users_relationships` WHERE
post_likes.idUser=users_relationships.idSub AND
users_relationships.idUser=$user_id AND post_likes.size >= 0
GROUP BY idPost ORDER BY id DESC
Answer the question
In order to leave comments, you need to log in
1) I can’t understand why you need id and size in the post_likes table. To register the fact and time of the like, this is enough: (idPost, idUser, date) with the key (idPost, idUser).
2) why ORDER BY id and not by date?
3) make the normal indexes you need, including the fields by which you filter and sort (indicating the sort order).
Under heavy load with such a task, it is better to try the graph database (when there are many connections, like you have with subscribers).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question