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
Effective Rust Canisters #8
Comments
let note_id = NEXT_NOTE.with(|counter_ref| {
let mut writer = counter_ref.borrow_mut();
*writer += 1;
*writer
}); |
On the question of Either way, I think that would be good to clarify. The leads me to other questions about the upgrade process. I’ll try to report back with my findings here. |
Some further questions:
|
For 2, I misunderstood. I thought that dfinity/cdk-rs#215 completely removed the storage API, but it didn't. It looks like |
Hi @paulyoung! Thanks a lot for your feedback!
The difference between
Surprisingly, I hear this question very often, I'll add a piece of advice on the topic. Basically, a simple counter should work in 90% of cases, just like database ID sequences. Many people opt for UUID, which is often an unnecessary complication.
Internet Identity was designed to store large amounts of data (currently, it uses ~4GiB of storage). |
Hi @roman-kashitsyn!
I was re-reading Effective Rust Canisters and I wanted to say thank you for writing it. It’s a great resource.
I had some questions/suggestions, particularly around generating sequential user numbers that I hoped you could help me with.
Thank you in advance!
Here, an example is given that uses
Cell
forNEXT_USER_ID
mmapped.blog/posts/01-effective-rust-canisters.html.pm
Line 44 in 7eaa016
But later it is explained that variables using
Cell
“flexible” and are discarded on upgrades.mmapped.blog/posts/01-effective-rust-canisters.html.pm
Line 159 in 7eaa016
mmapped.blog/posts/01-effective-rust-canisters.html.pm
Line 170 in 7eaa016
Would it make more sense to use
RefCell
in the original example?There are some examples of functions that take
UserId
:mmapped.blog/posts/01-effective-rust-canisters.html.pm
Line 217 in 7eaa016
mmapped.blog/posts/01-effective-rust-canisters.html.pm
Line 250 in 7eaa016
But there isn’t an example of how one might properly manage the creation of new user IDs (assuming they are incremental, like in
NEXT_USER_ID
)Could you provide an example of that?
Are there any pitfalls with something like the following?
What do you recommend?
There’s a link to Internet Identity:
mmapped.blog/posts/01-effective-rust-canisters.html.pm
Line 688 in 7eaa016
Internet Identity also has a sequential user number:
https://github.com/dfinity/internet-identity/blob/b434acea3831e4317cf20c26488f1d31570dd35b/src/internet_identity/src/storage.rs#L128-L140
However, it uses stable memory which is much more involved than using a stable variable. Could you explain why that is?
The text was updated successfully, but these errors were encountered: