Answer the question
In order to leave comments, you need to log in
How best to organize storage "like" -"not like" for articles or posts in the database?
For example, one ip address can vote for one post, the base is muscle, innoDB tables.
It is necessary to organize the storage of votes in the database with the least expenditure of resources and with the maximum speed of calculating the rating for the article.
I think the table structure is as follows:
article_id (int 11)
ip (varchar 15)
mark (enum ("-1", "1"))
PrimaryKey on the first two fields. Most likely, you can do it easier, share your experience, please.
Answer the question
In order to leave comments, you need to log in
Well, if you only need to count, then it is quite enough to simply add the rating field to the table with the article and increase / decrease its value programmatically.
The table is needed only when it is required to impose restrictions on time, ip address, etc. It is considered good form not to store the ip address as a string, but to write down its numerical value (if you write in php - php.net/manual/en /function.ip2long.php ).
Moreover, when displaying a news feed, it is very useful to store the aggregated value of the rating in a separate field in the table of articles - so as not to recalculate it every time. You can update it with a trigger on the DBMS side or programmatically.
by ip is not very good. some providers immediately hang 1 ip on a bunch of users, and mobile Internet users often have 1 ip on all
IMHO, it’s better to set a cookie with some unique token and look at it than by ip
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question