-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception on duplicate code insertion #9
Comments
Excellent idea. Will try to work on it. Or alternatively, I would be happy if you can create a pull request. |
I'll try to implement it this week. |
I created a pull request, see #10 |
Following with this idea, why not to check if the URL already exists on the table? I don't see any downside to this, even the click tracking will work, since it's the same URL. Right now I'm doing it this way: But I guess there would be a better/more effective way to do this if we include it inside the Thanks! :) |
@arietimmerman What dou you think about this? |
Thanks for the pull request @mxschll Wouldn't it be an idea to use some kind of encryption algorithm, and encrypt an incrementer? So this would look like this.
This should guarantee that the number of database lookups is very limited (only one). And the code runs deterministically. @diereysaa Depending on the application this could be very useful. In some applications you probably still want unique shortened url's, even though the same url is shorted. bitly always generates a unique url for example. |
You are right, the brute force approach is not ideal, especially if the database has lots of entries. However, an extremely large number of entries would be required before performance problems should arise. So I believe that this approach is manageable. I like the approach in #11 and that would be sufficient for me. Depending on the application, however, it could be problematic if the codes are not generated randomly, but rather follow a pattern. One could possibly adapt #10 in such a way that, depending on the number of entries in the database and the associated probability of a collision, the code length is increased in advance. Thus, one could reduce the database queries in advance and the code would still be random. |
Was the fix ever merged? Still getting that error when it tries to create a code with no characters '' |
Hello,
If a code is generated which already exists in the database, and it is then inserted into the database, an error is thrown.
I would suggest checking if the code already exists in the database in the creating() mtehod in URL.php. If so, a new code should be created until it does not already exist.
Perhaps one could also dynamically change the length of the code if too many collisions occur.
The text was updated successfully, but these errors were encountered: