Commit b0293d82 authored by David Haynes's avatar David Haynes 🙆
Browse files

Merge branch 'nanderson-fixcollision' into '2.2-dev'

Fix collision resolution

See merge request !85
parents c7362984 5bcb2200
Pipeline #1252 passed with stage
in 1 minute and 38 seconds
......@@ -134,14 +134,13 @@ class URL(models.Model):
"""
if cache.get("hashids_counter") is None:
cache.set("hashids_counter", URL.objects.count())
cache.incr("hashids_counter")
short = HASHIDS.encrypt(cache.get("hashids_counter"))
tries = 1
while tries < 100:
try:
URL.objects.get(short__iexact=short)
short = HASHIDS.encrypt(cache.get("hashids_counter"))
tries += 1
cache.incr("hashids_counter")
URL.objects.get(short__iexact=short)
except URL.DoesNotExist as ex:
print(ex)
return short
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment