I have implemented a like/unlike features for posts in one of my projects. The like table is normalized and has a column visible
. The schema is as follows:
Column Type Null Default Links to
id int(11) No
user_id int(11) Yes NULL user -> id
post_id int(11) Yes NULL posts -> id
visible tinyint(1) Yes NULL
created datetime No
updated datetime No
What I'm doing currently is that when a user likes a post, I create a record and when he un-likes it, I just set the visible
column to false. The count is calculated by post_id
and visible = true
. I did that to prevent excessive load on database when a user likes/unlikes a post.
My question is am I being paranoid in considering database performance so early (without much traffic) or is this among the best practices and I should continue with this?