Wanted to see if there is a consensus on where the logic for showing liked/unliked buttons be kept, at the client view or on the database query. Pushing the logic to the query itself keeps it clean and consistent, but would require every query for the home page list of posts to be personalized and not allow caching of that request.
Setup: MongoDb database (or possibly neo4j), node.js api and application server, iOS mobile client and website. Most posts can have a dozen or so likes, but a few will have hundreds of likes. Most users will have liked 50 - 300 posts, with a few users liking thousands of posts.
My Use Case: User browses a list of recent popular posts, and sees a "like" or "unlike" button next to each post based on whether they've already liked the post.
Solution-
Approach 1: pass the userid in the query to the database and return a list of the most popular posts with an isLiked property calculated in the query.
Approach 2: Client app fetches and keeps in sync the liked ids for that user and the view determines whether to show the "like" or "unlike" button for any given list of posts. The lists of posts can be cached on the server or in a cdn and doesn't require any personalization.
Approach 3? Is there a more efficient way to do it at the rest api service layer?