From df8399bca369c5a61e5581e76b7ce7e0bcfc731e Mon Sep 17 00:00:00 2001 From: Mia Winter Date: Thu, 18 Apr 2024 12:53:45 +0200 Subject: [PATCH] fixed Category Page not loading all categories on articles --- Wave/Components/Pages/CategoryView.razor | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/Wave/Components/Pages/CategoryView.razor b/Wave/Components/Pages/CategoryView.razor index 2e4a7ce..ad7c623 100644 --- a/Wave/Components/Pages/CategoryView.razor +++ b/Wave/Components/Pages/CategoryView.razor @@ -27,8 +27,8 @@ @Localizer["NotFound_BackToHome_Label"] } else {

@Localizer["Title"] - @Category.Name

- - + + } @code { @@ -42,22 +42,13 @@ protected override async Task OnInitializedAsync() { await using var context = await ContextFactory.CreateDbContextAsync(); string category = WebUtility.UrlDecode(CategoryName); - var now = DateTimeOffset.UtcNow; - // First load Category with simple chain and manual filters, as to minimize - // filter redundancy and query complexity (category -> Articles -> Author is linear) + if (Category != null) return; + Category = await context.Set() .IgnoreAutoIncludes().IgnoreQueryFilters() - .Include(c => c.Articles.Where(a => !a.IsDeleted && a.PublishDate <= now)) - .ThenInclude(a => a.Author) + .Include(c => c.Articles).ThenInclude(a => a.Categories) + .Include(c => c.Articles).ThenInclude(a => a.Author) + .AsSplitQuery() .FirstOrDefaultAsync(c => c.Name == category); - // Load all the other categories missing on the articles, by loading all relevant - // articles ID with their categories, so EF can map them to the already loaded entries - // (again manual filter to minimize redundancy) - await context.Set
() - .IgnoreAutoIncludes().IgnoreQueryFilters() - .Where(a => !a.IsDeleted && a.PublishDate <= now && a.Categories.Contains(Category!)) - .Select(a => new { - a.Id, a.Categories - }).LoadAsync(); } }