I have a upvote button, which the user can press and a vote will be registered. On clicking this button again, the vote gets cancelled.
So each press of this button is doing a DataBase Write. If an autoclicker is used on this button continuously, continuous DB calls will happen. I want to prevent this.
What can I do?
PS. I am sending an ajax query to the backend(running Django) when the upvote button is clicked.
You’d really want to check this on the server, so it doesn’t matter if someone disables javascript.
If you’re using PHP one option is to set a time limit between votes.. eg only allow one vote per minute.
So on every vote, store the time of the vote in a session variable, then ignore subsequent votes if it is within the time limit: