Closed powmedia closed 9 years ago
Thanks for the heads up!
Fixed in https://github.com/ericelliott/cuid/commit/d6bd849d66befe8290fb794e98dfcc1176f0e733
Slugs are 7 characters. =)
Having said that, one of the new slug IDs I've just seen created is 8 characters! On Nov 11, 2014 4:37 AM, "Eric Elliott" notifications@github.com wrote:
Slugs are 7 characters. =)
Reply to this email directly or view it on GitHub https://github.com/ericelliott/cuid/issues/16#issuecomment-62450623.
Oops. Is this causing problems? Maybe one of the entropy sources is just too short sometimes. I'd have to look at the implementation again and pad it for consistency.
It's not causing problems right now but would be good to know it was consistent.
On Tue, Nov 11, 2014 at 12:29 PM, Eric Elliott notifications@github.com wrote:
Oops. Is this causing problems? Maybe one of the entropy sources is just too short sometimes. I'd have to look at the implementation again and pad it for consistency.
Reply to this email directly or view it on GitHub https://github.com/ericelliott/cuid/issues/16#issuecomment-62500674.
Length is not guaranteed.
@ericelliott Could you explain what part of the cuid slug may vary in length? I'm wondering if this would affect the alphanumeric sortability of slugs.
To answer my own question, the counter portion of the slug grows unboundedly, which is why there is no guarantee on length.
The 2-character date representation comes before the counter, so I'd consider the resulting records well sortable across instances when generating IDs every few milliseconds. For anyone reading this, please note that I am no statistician. :)
Want to submit a PR?
@ericelliott for what? I'm OK with the slug growing unbounded mostly because I don't have a better strategy for keeping everything short while maintaining a reasonable guarantee of uniqueness.
Or did you mean a docs update? :) I can do this tomorrow.
Docs would be fine. =)
I ran into this again and did re-investigated the code (I am running a SQL DB with fixed column lengths). It turns out that my previous conclusion that the slug grows unboundedly is incorrect. :confused:
The actual max slug length is 10 characters as the counter will only ever contribute a max of 4 characters to the slug length. Therefore, slugs range for 7 - 10 chars. I'll update the README. Sorry about this!
The documentation states that IDs generated through cuid.slug() weigh in at 8 characters, however the ones I'm seeing are 7 characters. Is this expected behaviour? Does the documentation mean they will be up to 8 characters?