You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have a lot of records in ### Deque. We want to clear all records from Deque
In our cases we don't need to clear the data on the blockchain, we can overwrite it
Solution
I suggest adding a method clear for soft delete that sets Tail to 0.
OR
Change visibility methods from private to public
tail
head
set_tail
set_head
Temporary Solution
Now, I need to do it manually through the code
let full_key = namespaces_with_key(&["players".as_bytes()], b"t");
ctx.deps.storage.set(&full_key, &(0 as u32).to_be_bytes());
The text was updated successfully, but these errors were encountered:
Be careful with just setting the tail to 0!
When popping items from the front, the head gets incremented and when pushing to the back, the tail incremented. This is done in a wrapping way, so if the tail ever passes u32::MAX, it will start again at 0.
Because of that, the invariant for an empty Deque is not tail == 0, it is head == tail (if you never pop from / push to the front, those conditions are the same).
For that reason, I don't want to expose the setter functions (way too easy to mess up), but a clear function seems like something we should have
Problem
We have a lot of records in ### Deque. We want to clear all records from Deque
In our cases we don't need to clear the data on the blockchain, we can overwrite it
Solution
I suggest adding a method clear for soft delete that sets Tail to 0.
OR
Change visibility methods from private to public
Temporary Solution
Now, I need to do it manually through the code
The text was updated successfully, but these errors were encountered: