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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load theme + DisplayName from server after authentication.
|
// Fan out all independent post-auth calls in parallel to reduce initial load time.
|
||||||
// Non-fatal: if this fails the page still loads with default theme.
|
var themeTask = Task.Run(async () =>
|
||||||
// ThemeService.ScheduleSaveAsync() already logs errors internally.
|
{
|
||||||
try { await ThemeService.LoadFromServerAsync(); }
|
try { await ThemeService.LoadFromServerAsync(); }
|
||||||
catch { /* swallow — default theme remains active */ }
|
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
|
await Task.WhenAll(themeTask, featureTask, logosTask, typesTask, envelopesTask);
|
||||||
var logos = await CustomImagesService.GetAsync();
|
|
||||||
|
_canUseReceiverEnvelopeUrl = await featureTask;
|
||||||
|
|
||||||
|
var logos = await logosTask;
|
||||||
_appLogo = logos.App;
|
_appLogo = logos.App;
|
||||||
_companyLogo = logos.Company;
|
_companyLogo = logos.Company;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_envelopeTypes = (await EnvelopeTypeService.GetAsync()).ToList();
|
_envelopeTypes = (await typesTask).ToList();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -641,7 +648,8 @@
|
|||||||
_envelopeTypes = [];
|
_envelopeTypes = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
await LoadEnvelopesAsync();
|
// Use already-fetched envelope data instead of a second HTTP call.
|
||||||
|
await ApplyEnvelopeResultAsync(envelopesTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task LoadEnvelopesAsync()
|
async Task LoadEnvelopesAsync()
|
||||||
@@ -649,10 +657,15 @@
|
|||||||
_isLoading = true;
|
_isLoading = true;
|
||||||
_errorMessage = null;
|
_errorMessage = null;
|
||||||
await InvokeAsync(StateHasChanged);
|
await InvokeAsync(StateHasChanged);
|
||||||
|
await ApplyEnvelopeResultAsync(EnvelopeService.GetAsync(includeDocAndDocRes: false));
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task ApplyEnvelopeResultAsync(Task<IEnumerable<EnvelopeDto>?> envelopesTask)
|
||||||
|
{
|
||||||
|
_isLoading = true;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_allEnvelopes = await EnvelopeService.GetAsync(includeDocAndDocRes: false) ?? [];
|
_allEnvelopes = (await envelopesTask) ?? [];
|
||||||
|
|
||||||
// Split into active and completed based on effective status
|
// Split into active and completed based on effective status
|
||||||
// (history-aware: rejected envelopes should not stay in active tab).
|
// (history-aware: rejected envelopes should not stay in active tab).
|
||||||
|
|||||||
Reference in New Issue
Block a user