How to Set Up a Scalable Likes System? – Database


Is this even possible with bubble? Like for example, I can use Algeria to search for & store the full number of users who liked a post, and only show this data when I need itt, however, I’m not sure how to display individually, that a user has already liked a post.

I feel like having a list of likes on a user’s profile directly would be bad design.

Using a User-Container (satellite data type) and storing the likes in there would be slightly better except for the fact that I’d be constantly referencing the data type in order to conditionally show that a user has already liked a post via a red heart icon.

saving a list of users to the post itself, as “likes” and then grabbing the user from that list is what I do right now but its not scalable. What happens when I have a list of 1000+ likes? For every single post. bubble would be downloading a list of users who have liked the post.

Conversely, Instagram only downloads that data when you specifically ask to look at all of the likes a post has gotten. The minute you leave that page, they get rid of things.

This is the only scalable way because you can rely on the :count operator to not needlessly download more data

You can still stick a number of likes field on each post so you can sort by # of likes

I would go with a separate Like data type with 2 attributes: User and Post (or whatever users are going to see and giving likes for)
So for showing the number of likes under a post you’ll just need to count the number of Like items where Post is the post displayed.
Need to show “red heart” if current user liked some post? Check if “user – post” entry exists in Like table.
Need to show all users that liked the post? Extract the list of users from Like table where post is displayed post.

P.S. That’s what Tyler described in details above while I was typing :grinning:

You need to have a separate datatype for the likes, which links a User to the thing being liked.

Same answer as those that came before me with info on how to implement a like count on the Post:

Like data type.

Database trigger when Like is created: Make changes to Like’s Post (likes = This Post’s likes + 1).

Database trigger when Like is deleted: Make changes to Like’s Post (likes = This Post’s likes – 1)

To set the state of a like icon, do what Tyler said where it’s Do a search for Likes:count >= 1.



1 Like



Source link

Leave a Comment