If a post has 3 upvotes and 1 downvote it's score is being calculated as 4, rather than 2. It looks like when downvotes are being calculated in the database they are being subtracted, allowing them to go below zero, so subtracting a negative number ends up adding downvotes to upvotes, resulting in the incorrect score.
A solution would be not let the number of downvotes be negative. Everytime a post is downvoted it should increment the downvotes.
If a post has 3 upvotes and 1 downvote it's score is being calculated as 4, rather than 2. It looks like when downvotes are being calculated in the database they are being subtracted, allowing them to go below zero, so subtracting a negative number ends up adding downvotes to upvotes, resulting in the incorrect score.
A solution would be not let the number of downvotes be negative. Everytime a post is downvoted it should increment the downvotes.