-
Notifications
You must be signed in to change notification settings - Fork 1
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
Do card IDs have to be sequencial or just unique? #8
Comments
I really don't think that it makes sense to add another random 4 digit number. If you just use the unix timestamp, you instantly already have the card's creation date which you could show in the UI too. If someone really makes 2 cards in the same second you could just manually act like it was a second later instead. |
Okay, so just check if that ID is already in use and if so, increment it? |
If you want to be prepared just in case someone may make multiple cards in the same second that would work fine yeah. Just make sure it is unique in your DB and if you get a constraint failure, increment the number and try again. That's probably what I'll do in Android too when I get around to making the numbers timestamp-based. |
Okay. Another option might be to use the time with millisecond precision, because it's extremely unlikely someone will create two cards in one millisecond. Does Android let you access the Unix time in milliseconds? |
It is also extremely unlikely someone will create multiple cards in a single second. And SQLite natively supports storing UNIX timestamps as integer and Android (and most platforms) instantly understand it in less code. I really see no benefit in bloating your database size just to make an unlikely event even more unlikely given the workaround stays the same. |
Okay. Yeah, it is very unlikely that two cards will be created at once, so incrementing the value is probably the best option. |
We will need conflict resolution anyway in the case an user makes incompatible changes on two devices which both devices are offline. If we offer an option to keep either one version of the conflict or both (which would probably be implemented as copying the conflict into a new card) we'll have this issue solved too. |
Okay, sounds good. |
I'm thinking about generating card IDs as Unix time at creation, with a random 4-digit number appended (to avoid the problem of conflicting IDs if a user creates two cards in one second). Would it be a problem to have card IDs out of order as long as they were unique?
The text was updated successfully, but these errors were encountered: