Answer the question
In order to leave comments, you need to log in
What is the optimal structure for the "likes" table?
There are posts, there are users. You need to make them able to like posts.
The following structure immediately came to my mind:
create table `likes` (
`post_id` int,
`user_id` int,
foreign key (`post_id`) references `users`(`id`) on delete cascade,
foreign key (`user_id`) references `posts`(`id`) on delete cascade,
) engine=InnoDB, default character set = utf8;
Answer the question
In order to leave comments, you need to log in
If, purely theoretically, imagine that there are millions of users, and tens of millions of posts, is such a structure optimal?
A similar problem popped up, namely with likes.
The brakes were due to a clumsy code.
Since the number of users was already under 2 million, each post had from 1k to 30k, likes, respectively, for each post.
It was necessary to show a selection of users with accumulated likes.
We decided to do it on the client)))
The visitor selects an array of users, we quickly give him the basic data, and load ALL GARBAGE (likes, shmaiki, points) with a separate (almost flat instant request) in the background with Ajax.
What for to drag EVERYTHING at once? ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question