tedd / Tedd.ShortUrl

Simple URL shortening in ASP.Net 6.0 using MSSQL backend
https://go.tedd.no
GNU Lesser General Public License v2.1
5 stars 3 forks source link

Random key for url might already exist #22

Open dolphinsd opened 2 years ago

dolphinsd commented 2 years ago

While GetRandomKey is random, will million requests we made as a test, we had a hit for duplicates!

tedd commented 2 years ago

That is probably correct. Chance of collisions depends on number of existing entries and key length. It is compensated for somewhat in the code, but if you want a guarantee you could increase the count at https://github.com/tedd/Tedd.ShortUrl/blob/e845978589c8dda7066abb67c229cd95202b7238/src/Tedd.ShortUrl/Services/ShortUrlService.cs#L57 or even replace it with a while (true).

tedd commented 2 years ago

Come to think of it, I should probably make that a config option.