Answer the question
In order to leave comments, you need to log in
How to make your Like button (I like it)?
Interested in database storage.
Only one thing comes to mind:
We create a new table and store the id - post and id - user there, we get a many-to-many relationship. Both id's are indexes. And in order not to count how many likes a post has each time, add the `like` field in the table with the post and store the number there and simply display the number on the button.
I doubt that this is not the best option, you will still need to make a selection of all the likes from the 1st user. If there are 10,000 posts and 25,000 users, let's say only 10% of posts like, 10% of users, then the table will be (10.000/100*10)*(25.000/100*10)=2.500.000. I'm afraid that the selection of all likes from the 1st user will take a long time. At this rate, the number of rows can be very large, so how do you store such data? What is the limit in mysql?
Answer the question
In order to leave comments, you need to log in
SELECT *
FROM `forum_search_wordmatch`
WHERE `post_id` =127913
Запрос занял 0.0001 сек
The limit in MySQL is 255 nines. Those. you cannot store more than 9999 (255 times) records in one table :)
Sampling by PK (or, in your case, parts of it) is fast enough, but first ask yourself: do you need all the user's likes? I doubt that you want to display them on one page, because the user can like a lot and for a long time.
If the number of lines starts to exceed some reasonable number, some sharding algorithms can be applied. In any case, there are no special technical problems.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question