django-payments icon indicating copy to clipboard operation
django-payments copied to clipboard

Possible Improvement

Open thejasmeetsingh opened this issue 2 years ago • 3 comments

https://github.com/jazzband/django-payments/blob/7b23efdd36e6a1cdcf4e876caebce621565b8db2/payments/models.py#L118

Hey there, Can we add the current timestamp as well to the token string? UUID will give a unique value, but adding a timestamp can increase the probability that there will be fewer iterations and fewer chances that the program will encounter an infinite loop.

If you agree with the above observation, then please assign the issue to me! Thanks😊

thejasmeetsingh avatar Sep 16 '23 05:09 thejasmeetsingh

There exist 2^122 unique UUID4. Even on a database with billions of rows, the change of collision is negligible.

I think that the code in place is already an overkill; I doubt that this loop has ever had to try more than once.

WhyNotHugo avatar Sep 16 '23 14:09 WhyNotHugo

Yeah, that's true. I think it was initially put in as a fail-safe. But it can be optimized. Do you want me to work on this small thing?

thejasmeetsingh avatar Sep 16 '23 14:09 thejasmeetsingh

No, it is unnecessary. Unless you process billions of payments per seconds during several centuries, it is unlikely that you'll ever have a collision.

WhyNotHugo avatar Dec 02 '23 10:12 WhyNotHugo