How to catch the data from local storage fastly?

Haneen Al-fakhry 0 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;
        }
    }
}
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,370 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,386 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,254 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,238 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 55,686 Reputation points
    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. Zhi Lv - MSFT 32,011 Reputation points Microsoft Vendor
    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