Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
mrstebo9287yI would suggest adding a lock with a synchronisation object... But that is very anti-async 😅
-
@g-m-f you get a string and convert it to int64 that you use for the id.
Int64 because you can convert it back to the original string. (in the current case a 5 char string). -
jsmrcaga7807yUse UUIDs in front of your string. The probabiloty of collision is infinitely small (not mathematically speaking).
You could do
UUID∅yourString∅
∅ being some special char you don't use in the string..
I'm sure there has to be a simpler way :P -
The id(int64) is generated from a string that you need to be able to convert back to the original string. So none of the above work. And my question was not about the id but about the time between the check and the save.
Also only a-zA-Z0-9
😀 -
Kulijana4207yI know it should be async, but maybe do it as a transaction? You cant have full async and make it work regardless
-
zazapeta547yYou have to generate unique ids. That's all. If you can't generate unique id thus you can't ensure that is not already used. End of discussion.
And you have to accept something: you can't avoid collision. So, play around, and find a way to fix collisions. -
@zazapeta i agree its impossible to achieve the goal mentioned in my first post without loosing performance or making other sacrifices.
-
Kimmax109877y@SGrigorov it's either going to be the DB generating them, you generating them including locking, UID's or hoping driving a pseudo unique generator never collides with another id
No other way I could think of. -
Flygger19797yHow about going dirty and check the ID by inserting it? On fail it's taken and you try again, on success it's now reserved and you can go ahead and use it to update...
Related Rants
How would you handle this:
You generate an id
You chech the db if it is not taken
If it is taken you generate a new one and check again.
You then save the new item with the generated id.
How do you ensure that between the time you checked and the time you added the item some other call did not try to also add an item with the same id.
Async mvc
C# and dotnet core with ef core
question
c#
efcore
dotnet