R
R
riddlr2018-09-29 12:56:18
MongoDB
riddlr, 2018-09-29 12:56:18

How to make an effective likes system?

Faced difficulties how to think over an effective system of likes for posts-tweets. I am using NodeJS/Mongoose.
The first thing that comes to mind looks very inefficient, a bunch of unnecessary calculations. Since you need not just a likes counter, but also show a specific person whether he liked this tweet or not.
1. In the Tweet model, make the Likes field, where to put the ObjectID of all likes.
2. Thus, we can quite effectively count the number of likes (just the number of records)
3. But when the question is to show a specific person whether he liked or not, we will have to send a list of all those who liked it to the client and find a match with the person's ID there. This looks stupid - why would I send an array of 10,000 like records to the client, only to find a match there?
4. And to make a separate endpoint only for the like status, where to calculate these values ​​​​separately looks too bold (there will be a lot of similar functionality, and there will be too much confusion)
Also, the question is separate from Monga, according to the API. I have it all goes according to REST. Therefore, all this should be received in one request, when the user opens the page with the tweet feed. How to think it through?
How do they solve such a problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question