Optimize post-auth calls with parallel execution
Refactored the code to improve performance by parallelizing independent post-authentication service calls using `Task.WhenAll`. This reduces the initial page load time by avoiding redundant HTTP calls and reusing pre-fetched data. - Moved `ThemeService.LoadFromServerAsync` to a separate task. - Parallelized service calls for theme, logos, envelope types, and envelopes. - Introduced `ApplyEnvelopeResultAsync` to process envelope data. - Updated `LoadEnvelopesAsync` to reuse pre-fetched envelope data. - Removed redundant HTTP calls to streamline initialization logic.
This commit is contained in:
@@ -618,22 +618,29 @@
|
||||
return;
|
||||
}
|
||||
|
||||
// Load theme + DisplayName from server after authentication.
|
||||
// Non-fatal: if this fails the page still loads with default theme.
|
||||
// ThemeService.ScheduleSaveAsync() already logs errors internally.
|
||||
// Fan out all independent post-auth calls in parallel to reduce initial load time.
|
||||
var themeTask = Task.Run(async () =>
|
||||
{
|
||||
try { await ThemeService.LoadFromServerAsync(); }
|
||||
catch { /* swallow — default theme remains active */ }
|
||||
});
|
||||
|
||||
_canUseReceiverEnvelopeUrl = await EnvelopeReceiverService.GetReceiverEnvelopeUrlFeatureEnabledAsync();
|
||||
var featureTask = EnvelopeReceiverService.GetReceiverEnvelopeUrlFeatureEnabledAsync();
|
||||
var logosTask = CustomImagesService.GetAsync();
|
||||
var typesTask = EnvelopeTypeService.GetAsync();
|
||||
var envelopesTask = EnvelopeService.GetAsync(includeDocAndDocRes: false);
|
||||
|
||||
// Load logo config — authenticated, so this should succeed
|
||||
var logos = await CustomImagesService.GetAsync();
|
||||
await Task.WhenAll(themeTask, featureTask, logosTask, typesTask, envelopesTask);
|
||||
|
||||
_canUseReceiverEnvelopeUrl = await featureTask;
|
||||
|
||||
var logos = await logosTask;
|
||||
_appLogo = logos.App;
|
||||
_companyLogo = logos.Company;
|
||||
|
||||
try
|
||||
{
|
||||
_envelopeTypes = (await EnvelopeTypeService.GetAsync()).ToList();
|
||||
_envelopeTypes = (await typesTask).ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -641,7 +648,8 @@
|
||||
_envelopeTypes = [];
|
||||
}
|
||||
|
||||
await LoadEnvelopesAsync();
|
||||
// Use already-fetched envelope data instead of a second HTTP call.
|
||||
await ApplyEnvelopeResultAsync(envelopesTask);
|
||||
}
|
||||
|
||||
async Task LoadEnvelopesAsync()
|
||||
@@ -649,10 +657,15 @@
|
||||
_isLoading = true;
|
||||
_errorMessage = null;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
await ApplyEnvelopeResultAsync(EnvelopeService.GetAsync(includeDocAndDocRes: false));
|
||||
}
|
||||
|
||||
async Task ApplyEnvelopeResultAsync(Task<IEnumerable<EnvelopeDto>?> envelopesTask)
|
||||
{
|
||||
_isLoading = true;
|
||||
try
|
||||
{
|
||||
_allEnvelopes = await EnvelopeService.GetAsync(includeDocAndDocRes: false) ?? [];
|
||||
_allEnvelopes = (await envelopesTask) ?? [];
|
||||
|
||||
// Split into active and completed based on effective status
|
||||
// (history-aware: rejected envelopes should not stay in active tab).
|
||||
|
||||
Reference in New Issue
Block a user