Foreach vs Count with likes table
Guys I made a Vote(likes and dislikes) table. It's similar to reddit's karma system. Dislikes decrease the likes. So far so good but now I am using foreach to check if vote is True or False and do the calculation. Would it be faster if i made a two different table and just use likes.Count - dislikes.Count instead?
50 Replies
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
sql table
mssql
Front end
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
then two different tables for likes and dislikes
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
yes but that's not api. It's my controller and its models
there are more columns in vote
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
how do i do that in sql database?
another column perhaps?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
no i mean the calculation. How do I do that in database?
I thought you meant calculating and writing it in an another column
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
in a moment
it froze lol, a minute more
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
yup
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
do you mean api?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
finally, i was trying to understand why you was talking about database calculation
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
btw, i am returning a list of post like this;
i guess i have to add that code into the dto
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
wait a min I am confused 😄
will postdto have a custom property for the karma value?
do I calculate it in constructer or something?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
i am not sure if i want to use linq or not 😄
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I did a thing like that. Last part is completely random, I just added it for reasons 😄
anyway, i am gonna eat something, i will be back in 20 min if you want to say something, thanks for the help!
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I use body for the main focus on tables. Body can be the text in comment for example
Would this even work? I have no idea
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
no i don't mean your idea
the constructer
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
yeah i didn't do it for that exact reason
whose vote is this?
you know
you can add an another many to many table to tell that user voted this post already. But at this point I can just use a vote table
wait a minute
it worked lol
i feel like crazy scientist
it even worked for the individual posts which uses this dto with inheritence
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
3?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
is it because sql uses bit?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
was 3 True?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
not sure i am following
it's bool
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
tebeco#0205
post.votes.Count(v => v.Body)
Quoted by
<@!689473681302224947> from #Foreach vs Count with likes table (click here)
React with ❌ to remove this embed.
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
this is the first time i am hearing about this 😄
oh the logic you mean
body returns true or false
why 3?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
ooohhhh, I thought we was talking about v => v.Body == 3 or something
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
😄 see you
okay case closed. Thanks @Eugene
not you tobeclone, you confused me for 5 minutes 😠
even if it's my fault
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View