I am working on a Blazor Webassembly Application. In my solution I have two projects. One is for front end and that is Blazor Webassembly project. 2nd project is .net core WebAPI project. This API project has many [HTTPGet] end points. In one of my razor page I have to call 5 APIs to work on them. These API calls bring data from different database tables. Each table contains more than 60,000 records. Please see the code below:
protected override async Task OnInitializedAsync()
{
try
{
// Lists
MasterLocalMemberList = await Http.GetFromJsonAsync<List<MemberLocal>>("api/member/getlocalmembers");
MasterInternationalMembeList = await Http.GetFromJsonAsync<List<MemberInternational>>("api/member/getinternationalmembers");
MasterVisitorList = await Http.GetFromJsonAsync<List<Visitor>>("api/member/getvisitors");
MasterTablighGuestList = await Http.GetFromJsonAsync<List<TablighGuest>>("api/member/gettablighguests");
AttendanceList = await Http.GetFromJsonAsync<List<Attendance>>("api/member/getattendance");
CountryList = await Http.GetFromJsonAsync<List<MemberCountry>>("api/member/getcountries");
GateList = await Http.GetFromJsonAsync<List<Gate>>("api/member/getgatelist");
gateNumber = await SessionStorage.GetItemAsync<int>("GateNumber");
gateNumber = (gateNumber == null ? 1 : gateNumber);
GateType = GateList.Where(x => x.GateID == gateNumber).First().GateType;
//await mudSelectItemCountry.SelectOption(SelectedCountry);
UpdateMembersListByCountry();
}
catch (Exception emx)
{
//throw;
}
}
This method takes much time to execute. I am using EntityFrameworkCore. Once the page is loaded then rest executions are very fast i.e. saving , updating and deleting records into database. Please suggest appropriate solution. Thanks
You will need to provide more info on what each of these calls does on the server. If you are loading entire tables into entities and serializing those into JSON then sending those back, you are likely loading and sending far more columns than are needed, and potentially hitting lazy loading with the serialization. Hooking a profiler up to the database will reveal lazy loading queries. (many more than 5 expected SQL statements being run)
Things to improve performance:
Select
to populate that from the entity in the query. This sends 2 fields instead of an entire table's columns and avoids possible lazy-loading.