From 3e570a40a2b491dd41b6f9f0030f3cf2218b2acc Mon Sep 17 00:00:00 2001 From: Max <51083570+DRdrProfessor@users.noreply.github.com> Date: Sat, 24 Jun 2023 10:15:51 +0200 Subject: [PATCH] Reworked fetching of categories. --- SharpRss/DbAccess.cs | 2 -- SharpRss/Services/SyndicationService.cs | 15 ++++++++++++++- WebSharpRSS/Shared/SideGuide.razor | 4 ++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/SharpRss/DbAccess.cs b/SharpRss/DbAccess.cs index 0d9060f..0c0d670 100644 --- a/SharpRss/DbAccess.cs +++ b/SharpRss/DbAccess.cs @@ -48,8 +48,6 @@ namespace SharpRss Icon = reader["icon"].ToString(), LastUpdated = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(reader["last_updated"].ToString())) }; - categoryModel.Syndications = await GetSyndicationsAsync(new []{ categoryModel.Id }); - //categoryModel.SyndicationCount = await dbc.ExecuteScalarAsync($"SELECT COUNT(*) FROM syndication WHERE category_id=@CatId", new { CatId = categoryModel.Id }); categories.Add(categoryModel); } return categories; diff --git a/SharpRss/Services/SyndicationService.cs b/SharpRss/Services/SyndicationService.cs index 02856d4..3ca65b3 100644 --- a/SharpRss/Services/SyndicationService.cs +++ b/SharpRss/Services/SyndicationService.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Argotic.Common; using Argotic.Syndication; @@ -29,7 +30,19 @@ namespace SharpRss.Services public async Task CreateCategoryAsync(CategoryModel category) => await DbAccess.SetCategoryAsync(category); - public async Task> GetCategoriesAsync() => await DbAccess.GetCategoriesAsync(); + + public async Task> GetCategoriesAsync() + { + HashSet categories = await DbAccess.GetCategoriesAsync(); + foreach (CategoryModel catModel in categories) + { + catModel.Syndications = await DbAccess.GetSyndicationsAsync(new[] { catModel.Id }); + } + return categories; + } + + private async void ForEachCategories(CategoryModel x) => x.Syndications = await DbAccess.GetSyndicationsAsync(new[] { x.Id }); + public async Task AddSubscriptionAsync(string url, CategoryModel? category = null) { var syndication = SyndicationManager.CreateSyndication(url); diff --git a/WebSharpRSS/Shared/SideGuide.razor b/WebSharpRSS/Shared/SideGuide.razor index a521677..25be3e0 100644 --- a/WebSharpRSS/Shared/SideGuide.razor +++ b/WebSharpRSS/Shared/SideGuide.razor @@ -62,8 +62,8 @@ private async void ExpandedChanged(TreeItemData treeItemData) { treeItemData.Loading = true; - var groupedItems = await _syndicationService.GetFeedsAsync(treeItemData.CategoryModel?.Id); - treeItemData.Children = ModelToTreeItem(groupedItems); + if (treeItemData.CategoryModel != null) + treeItemData.Children = ModelToTreeItem(treeItemData.CategoryModel.Syndications); treeItemData.IsExpanded = !treeItemData.IsExpanded; treeItemData.Loading = false; StateHasChanged();