Skip to content

Commit

Permalink
#480 - Ensure that all templates are loaded at least once
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed Jun 14, 2023
1 parent 470d088 commit 53339ff
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Money.Blazor.Host/Services/ExpenseTemplateMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ internal class ExpenseTemplateMiddleware : HttpQueryDispatcher.IMiddleware,
private readonly ExpenseTemplateStorage localStorage;
private readonly ILog log;

private bool areModelsLoadedAtLeastOnce;
private readonly List<ExpenseTemplateModel> models = new List<ExpenseTemplateModel>();
private Task listAllTask;

Expand All @@ -49,14 +50,15 @@ public async Task<object> ExecuteAsync(object query, HttpQueryDispatcher dispatc

private async Task EnsureListAsync(HttpQueryDispatcher dispatcher, HttpQueryDispatcher.Next next, ListAllExpenseTemplate listAll)
{
if (models.Count == 0)
if (models.Count == 0 || !areModelsLoadedAtLeastOnce)
{
if (listAllTask == null)
listAllTask = LoadAllAsync(dispatcher, next, listAll);

try
{
await listAllTask;
areModelsLoadedAtLeastOnce = true;
}
finally
{
Expand Down

0 comments on commit 53339ff

Please sign in to comment.