S
S
svem2011-02-02 13:22:25
MySQL
svem, 2011-02-02 13:22:25

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

3 answer(s)
D
Dunadan, 2011-02-02
@Dunadan

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.

I
Iskander Giniyatullin, 2011-02-02
@rednaxi

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

D
Dmitry, 2011-02-02
@deemytch

An addition to the previous speaker is a sad experience - you can’t get rid of cheating. It can only be minimized by a combination of administrative and technical methods.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question