There’s some functionality on our Django app that displays a link to refresh some information from our version control system. This is simply a link, and when they hit that URL the actions of going to version control, getting the information, checking it against the database and updating the database are performed.
Recently we had a user click the ‘refresh’ button twice for one asset. This resulted in the URL being hit twice, so the operations were performed twice and eventually a duplicate entry was created in our database.
We need to do something to remove the possibility of the user clicking that button twice. Should we move from a link to a javascript button? Should we set some flag in request.session as soon as the first click happens, then unset it upon completion, and always check that flag when performing a refresh? Those are just two ideas that seem feasible, but I really don’t know.
You should use
POSTrequest and redirect after it, really.Also, to prevent double submitting, you can employ a solution like one from this question: Does a library to prevent duplicate form submissions exist for django?. You can store a key
refreshing_vcsinrequest.sessionand check its value in your view. If the data is already being refreshed, then you can redirect user to another page and tell to wait a bit.Completely another way would be to setup a
django-celerytask (or simply use cron) to perform updates at regular intervals automatically, but I don’t know whether it suit your requirements.