Key out of sync with short url's ID #188
Replies: 1 comment 1 reply
-
Hey @fhusquinet! First off, I'm really sorry that you ran into that problem because of the package! 😞 Am I right in saying that your I'd definitely be open to adding some kind of option or method (e.g. - Do you think something like this would probably help you in this case? |
Beta Was this translation helpful? Give feedback.
-
Hi!
Yesterday evening, I've noticed a lot of my queue emails were failing in Horizon after a 60s timeout. Usually, they don't take more than 3-4s to process, sometimes a bit more if a few things had to be processed first.
After digging in, I've noticed that the KeyGenerator@generateRandom() method had to do its do while loop about 17 thousands time to find a unique key. This caused a lot of database queries, and unnecessary strain on my MySQL instance, and ultimately caused the timeout issue. I've fixed it by increasing the key length for 10 to 12, basically "resetting" this check, but I'm curious if anyone encountered this?
The method's comment state that it should be pretty rare for one key to collide with an existing ID, but after checking my database the model with the ID of 161089 had a key matching the ID 179014...
Obviously once an ID collides, all future checks will always collides as well forcing the app to do one extra loop at the very least, but in my case it's a lot more...
Note that my app contains about 175k rows now, since September 2019.
This might be a bit out of the scope of the package, but I was thinking about maybe logging if this issue occurs. Like throwing an exception that doesn't stop the execution of the loop but simply warns the user that the data might be falling out of sync if it has to execute more than X times?
It might also be less performant, but it would also be possible to decode the last key found and increment its value instead of the ID. Obviously I could do this inside a custom key generator class, but if anyone had this issue it might be worth considering adding a few checks in the package directly, it wasn't a fun issue to debug I have to say... 😅
Beta Was this translation helpful? Give feedback.
All reactions