Check if user already voted this post or comment [Answered]
I want to fill the like/dislike buttons with color if they are already voted by the user. Which one would be faster and more economic;
-Fetching the votes of the parent post/comment from the start, then checking if this user's id is there or...
-Another request to the api to check if user has a record already with that post's id in votes table.
31 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
no no of course not. My api sends me the related vote records
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
i am sending them I guess. Every vote which belongs to that post for example.
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
i am also getting the count of votes, without bringing vote list.
so i don't actually need vote list
as i said, i am looking for alternative
i don't want to send them
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
i already did those
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
i just need to fill the btns with color when user refreshes for example
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
js don't have the list of votes, i will give the codes in a min
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
api:
and constructor in api has this
Then I get those with controller from my app (temporary, i will use fetch later)
Then I am checking if the logged in user id is in post.votes and filling the post accordingly
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
true or false. It's votes table, not dislike and like
true means liked, false means disliked
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
well, i am getting the votes with account id and body, so i can check if the logged in user has his vote there. But I only applied it to one page
liked, dislike, take the vote back etc all working pretty well, i remastered it yesterday
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
there is no problem with that, i can change a couple of aspects and make it better of course
but it's not really a problem right now. My problem is the speed. I am getting all the damn votes and giving it to the client 😄
app at least, not client
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
cshtml, it doesn't actually send them to the client.
my server has them
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
you may be right i didn't check
i give them all to the viewmodel
i don't know if client has access to it
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
i have no idea honestly. It's local host app and i have like 10-20 vote records 😄
but i imagine if it was 5000, for each post they will see, maybe a couple of fetch request would do way better job
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
welp, then i am sticking with this, i would only delete a couple of lines if i change my mind
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
thanks!
✅ This post has been marked as answered!