How to catch the data from local storage fastly?

Haneen Al-fakhry 10 Reputation points
2023-01-18T10:12:13.4333333+00:00

I have a data in localStorage I catch them by OnInitializedAsync method in mainLayout component and pass them to many component but it spends a lot of time how to inhance it ? this is my code

Notes: the number of Items in list which I catch from local storage is more than 3000, the method spend more than 15000 milliseconds, and I am using chrome browser


<div class="page">
        <NavMenu/>
        <CascadingValue Value="this">
            <main class="margin-page container px-0">
                <article class="px-1">
                    @Body
                </article>
            </main>
        </CascadingValue>
</div>
@code
{
    public List<Product> product { get; set; } = new List<Product>();
    Navbar navbar { get; set; }
    
    protected async override Task OnInitializedAsync()
    {
        await GetProducts();

        await base.OnInitializedAsync();
    }

    public async Task GetProducts()
    {
        var result = await _localStorageService.GetItem<List<Product>>("Items");
        if (result is not null)
        {
            product = result;
        }
    }
}
Developer technologies | .NET | Blazor
Developer technologies | .NET | Other
Developer technologies | ASP.NET | Other
Developer technologies | C#
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 78,006 Reputation points Volunteer Moderator
    2023-01-18T19:33:25.1866667+00:00

    you don't say if this is client (WASM) or server blazor. I assume, its server, and the delay is sending the list up the signal/r connection.

    if using server, then only store the key in local storage, and store the data is server persistent store.


  2. Anonymous
    2023-01-19T05:40:03.17+00:00

    Hi @Haneen Al-fakhry

    the number of Items in list which I catch from local storage is more than 3000, the method spend more than 15000 milliseconds, and I am using chrome browser

    Try to use pagination to display data, such as 50 records per page, it will reduce the data query time.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    Dillion


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.