char0n / django-brevisurl

Django app for shortening urls
Other
9 stars 10 forks source link

use get_or_create for shorten_url retries #26

Closed smaggs closed 6 years ago

smaggs commented 8 years ago

If the initial get_or_create fails in shorten_url, we enter an infinite loop of create() attempts. If the initial failure was due to competition with another instance of trying to shorten the same URL, then the subsequent create() call will never succeed and the code will spin until killed.

This commit changes the retries to use get_or_create as well, so that the retry will not try to create a short url that already exists.

It might also be worth changing while True to something finite, like for _ in range(20), but that is left for another day.

char0n commented 8 years ago

@beld2107, could you please review this pull request ?

beld2107 commented 8 years ago

I think it's fine. Eventually I would say some of the code could be extracted in a function to avoid having completely duplicate code twice in that function.