I’m writing an api in nodejs and I’m trying to figure out how twitter and facebook shows posts from only the people that we follow.. My initial thought was loop through the posts and filter them according to followers ID, but that consumes a lot of CPU because we’ve to the loop through all the posts in the MySQL DB. What is the correct logic to show only the tweets/posts from the subscribed people/friends
I would be grateful if someone could through some light.
2
Answers
You don’t have to loop through all of them. You have the IDs of your friends, you can call directly to them.
Now I’m not sure if Indexes are being used in this scenario, but I’d personally use them.
Isn’t this what you want?
https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-home_timeline.html
Just remove your posts from the result set.