Skip to content

[Bad Example] Be Careful With Storage Growth #14

@shawntabrizi

Description

@shawntabrizi

https://libro.blockdeep.dev/high/Be_Careful_With_Storage_Growth.html

fn add_entry_limited(entry: u32) -> Result<(), Error> {
    Entries::<T>::try_mutate(|entries| {
        entries.try_push(entry).map_err(|_| Error::<T>::TooManyEntries)?;
        Ok(())
    })
}

There should be a try_push api directly on the storage item, which is much more efficient than doing try_mutate.

In fact, that should probably be its own best practice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions