Skip to content
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

Open
kj7rrv opened this issue Jan 25, 2022 · 8 comments
Open

Do card IDs have to be sequencial or just unique? #8

kj7rrv opened this issue Jan 25, 2022 · 8 comments

Comments

@kj7rrv
Copy link

kj7rrv commented Jan 25, 2022

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?

@TheLastProject
Copy link
Member

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.

@kj7rrv
Copy link
Author

kj7rrv commented Jan 25, 2022

Okay, so just check if that ID is already in use and if so, increment it?

@TheLastProject
Copy link
Member

TheLastProject commented Jan 25, 2022

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.

@kj7rrv
Copy link
Author

kj7rrv commented Jan 25, 2022

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?

@TheLastProject
Copy link
Member

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.

@kj7rrv
Copy link
Author

kj7rrv commented Jan 25, 2022

Okay. Yeah, it is very unlikely that two cards will be created at once, so incrementing the value is probably the best option.
The only other problem I can think of is if the user is using two devices with sync. If the user creates one card on each device simultaneously, Catima won't detect the discrepancy until they sync. What should happen then?

@TheLastProject
Copy link
Member

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.

@kj7rrv
Copy link
Author

kj7rrv commented Jan 25, 2022

Okay, sounds good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants