I have a voting script that stores post_id and user_id in a table to determine if a particular user voted for a message and banned them in the future.
To do this, I perform the following 3 queries.
SELECT user_id, post_id from votes_table where postid=? AND user_id=?
If this does not return rows, then:
UPDATE post_table set votecount = votecount-1 where post_id = ?
Then
SELECT votecount from post where post_id=?
To display a new voting score on a web page
Is there a better way to do this? 3 requests seriously slow down the user voting process
Edit
- In the vote table, vote_id is the primary key
- In the message table, post_id is the primary key.
- Any other suggestions to speed things up?
source
share