Function frame_support::storage::unhashed::clear_prefix

source ·
pub fn clear_prefix(
    prefix: &[u8],
    maybe_limit: Option<u32>,
    _maybe_cursor: Option<&[u8]>,
) -> MultiRemovalResults
Expand description

Partially clear the storage of all keys under a common prefix.

§Limit

A limit should always be provided through maybe_limit. This is one fewer than the maximum number of backend iterations which may be done by this operation and as such represents the maximum number of backend deletions which may happen. A limit of zero implies that no keys will be deleted, though there may be a single iteration done.

The limit can be used to partially delete storage items in case it is too large or costly to delete all in a single operation.

§Cursor

A cursor may be passed in to this operation with maybe_cursor. None should only be passed once (in the initial call) for any attempt to clear storage. In general, subsequent calls operating on the same prefix should pass Some and this value should be equal to the previous call result’s maybe_cursor field. The only exception to this is when you can guarantee that the subsequent call is in a new block; in this case the previous call’s result cursor need not be passed in an a None may be passed instead. This exception may be useful then making this call solely from a block-hook such as on_initialize.

Returns MultiRemovalResults to inform about the result. Once the resultant maybe_cursor field is None, then no further items remain to be deleted.

NOTE: After the initial call for any given child storage, it is important that no keys further keys are inserted. If so, then they may or may not be deleted by subsequent calls.

§Note

Please note that keys which are residing in the overlay for the child are deleted without counting towards the limit.