V
V
Vadim Stepanenko2021-10-21 19:10:42
Database design
Vadim Stepanenko, 2021-10-21 19:10:42

Remove likes from the database or set isActive = 0?

I heard that in the database, when deleting a record, it is better not to delete it, but to set the isActive = 0 flag, for example, and not take it into account in the selections due to disk fragmentation (?).

Now I am writing the logic for likes on posts and wondered how best to do it:
1. The easiest option is to remove likes from the database when unlike and insert when like
2. When unlike post, set the isActive = 0 flag. There are two scenarios in the same post: re-insert like (in this case, if the user clicks "like" - "unlike" a bunch of times, then the table will have a lot of extra records. The second option is to look for whether the table has a like for a post with isActive = 0 and just set isActive = 1. If there is no record, then insert it, but then the logic and the number of requests to the database grows (it seems to me that I just invented the wheel).

How would you implement such a mechanism?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
iBird Rose, 2021-10-21
@Vadim1899

use INSERT ... ON DUPLICATE KEY UPDATE https://dev.mysql.com/doc/refman/8.0/en/insert-on-...
by user_id tobish

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question