开发者

What about storing the like & dislike count in my article table?

开发者 https://www.devze.com 2023-03-14 02:11 出处:网络
I developed a like/dislike vote system. Pretty simple, a vote table where there are article_id, vote_type (-1 or +1)

I developed a like/dislike vote system.

Pretty simple, a vote table where there are article_id, vote_type (-1 or +1)

Two avoid such SELECT SUM(vote_type) FROM vote WHERE vote_type = +1 I had the idea to store that count in my article table using an Event/Listener system.

W开发者_运维知识库hat do you think about that?


This type of doing things (denormalization) is a very standard practice when performance is much more important than data integrity. So IMHO it's more than OK to do it in your case, as you don't really care if the "like" count for a page becomes slightly off for some reason.

However, you might need to store the likes one-per-row anyway if you want to also save information such as who liked what, timestamps, etc. Which in no way invalidates what I said in paragraph above.


What ever system you will use the matter will not change.
You still need to have a table like now with article_id, vote_type (-1 or +1)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号