I'm facing some troubles by trying to make a like/unlike system for my app.
It's okay when i like/unlike in a normal timelapse, but when i click multiple times in a very short frequency (20 clicks in 10 seconds for example) then my counter is disturbed.
Normally while i'm testing my counter should always have a value of 1 or 0 since i am the only one to do the operation. However when i click quickly and multiple times, my rest api cannot follow the rythm and i'm getting a counter that have 7 or 8 likes.
I've tried multiple solutions. first by adding the model transaction included with django. As a decorator :
@transaction.atomic
Or manually :
with transaction.atomic():
#do stuff
I've also tried to increment directly from the database by using F()
:
votes=F("votes") + 1
Nothing seems to work.
Any suggestion ?