Keeping an “like” item in the database?

I am running a Rails application in Postgres through Heroku.

I would like to similarly like Facebook on my site for various elements, such as user comments. What is the smartest way to store them in my database that will be efficient and fast?

The obvious is simply the presence of a connection table between users and elements, something like this:

user_id int
item_id int
item_type string
created_at datettime

However, when displayed, this will mean that every time I pull out an element, I will need to join the join over an entire similar table, which can become very large.

The obvious answer for this would be to store the counter in the elements, for their constant quantity, like counting. However, this will not work, because whoever liked the item, both to display next to the element and to hide a similar button for things that the user already liked.

My plan is to add a text box to all the pretty elements in which I would store a serialized array. Thus, each attraction of the subject will be accompanied by a complete list of those who like it. Is there a better way to do this, or is this the recommended approach?

+3
source share
1 answer

, , ? Postgres, , RDBMS, . -, , . , .

. , , . , - , /, . , , .

+7

Source: https://habr.com/ru/post/1756366/


All Articles