B
B
Billy Milligan2014-02-13 01:26:56
PHP
Billy Milligan, 2014-02-13 01:26:56

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

4 answer(s)
S
Stepan, 2014-02-13
@Billy_Milligan

SELECT * 
FROM  `forum_search_wordmatch` 
WHERE  `post_id` =127913

Запрос занял 0.0001 сек

The table has 20 million records.
If you are going to store userid, time, postid then 1 record will take a maximum of 40 bytes. In other words: 1Gb ~ 35-40M records.

A
Alexander Wolf, 2014-02-13
@mannaro

The limit in MySQL is 255 nines. Those. you cannot store more than 9999 (255 times) records in one table :)

Y
Yuri Morozov, 2014-02-13
@metamorph

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.

2
2slide, 2014-02-13
@2slide

If you make a like field in the post table. And store there a selection from the table with likes.
Run a selection for the like field via cron, for example, once an hour.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question