mirror of
https://github.com/hmaxnl/SharpRSS.git
synced 2025-01-18 21:04:21 +01:00
Broken, rework DbAccess to only get and set db data.
This commit is contained in:
parent
11f8425b3f
commit
dfc9db7944
|
@ -13,8 +13,8 @@ namespace SharpRss.Core.Cache
|
||||||
|
|
||||||
internal static class TempCache
|
internal static class TempCache
|
||||||
{
|
{
|
||||||
private static Dictionary<string, CategoryModel> _categoryCache = new Dictionary<string, CategoryModel>();
|
public static Dictionary<string, CategoryModel> CategoryCache { get; private set; } = new Dictionary<string, CategoryModel>();
|
||||||
private static Dictionary<string, SyndicationModel> _syndicationCache = new Dictionary<string, SyndicationModel>();
|
public static Dictionary<string, SyndicationModel> SyndicationCache { get; private set; } = new Dictionary<string, SyndicationModel>();
|
||||||
|
|
||||||
public static async Task UpdateCache(CacheFetch cf)
|
public static async Task UpdateCache(CacheFetch cf)
|
||||||
{
|
{
|
||||||
|
@ -22,16 +22,16 @@ namespace SharpRss.Core.Cache
|
||||||
{
|
{
|
||||||
case CacheFetch.Category:
|
case CacheFetch.Category:
|
||||||
var cats = await DbAccess.GetCategoriesAsync();
|
var cats = await DbAccess.GetCategoriesAsync();
|
||||||
_categoryCache = cats.ToDictionary(x => x.Id);
|
CategoryCache = cats.ToDictionary(x => x.Id);
|
||||||
break;
|
break;
|
||||||
case CacheFetch.Syndication:
|
case CacheFetch.Syndication:
|
||||||
var syndications = await DbAccess.GetSyndicationsAsync();
|
var syndications = await DbAccess.GetSyndicationsAsync();
|
||||||
_syndicationCache = syndications.ToDictionary(x => x.EncodedUrl);
|
SyndicationCache = syndications.ToDictionary(x => x.EncodedUrl);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CategoryModel? GetCategory(string catId) => _categoryCache.TryGetValue(catId, out CategoryModel catModel) ? catModel : null;
|
public static CategoryModel? GetCategory(string catId) => CategoryCache.TryGetValue(catId, out CategoryModel catModel) ? catModel : null;
|
||||||
public static SyndicationModel? GetSyndication(string encodedUrl) => _syndicationCache.TryGetValue(encodedUrl, out SyndicationModel synModel) ? synModel : null;
|
public static SyndicationModel? GetSyndication(string encodedUrl) => SyndicationCache.TryGetValue(encodedUrl, out SyndicationModel synModel) ? synModel : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -12,6 +12,7 @@ using SharpRss.Models;
|
||||||
|
|
||||||
namespace SharpRss
|
namespace SharpRss
|
||||||
{
|
{
|
||||||
|
//TODO: Need rework to only get from db syndication service will handle extra data.
|
||||||
internal static class DbAccess
|
internal static class DbAccess
|
||||||
{
|
{
|
||||||
private static readonly string ConnectionString = $"Data Source={Path.Combine(Environment.CurrentDirectory, "sharp_rss.sqlite")};";
|
private static readonly string ConnectionString = $"Data Source={Path.Combine(Environment.CurrentDirectory, "sharp_rss.sqlite")};";
|
||||||
|
@ -47,7 +48,8 @@ namespace SharpRss
|
||||||
Icon = reader["icon"].ToString(),
|
Icon = reader["icon"].ToString(),
|
||||||
LastUpdated = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(reader["last_updated"].ToString()))
|
LastUpdated = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(reader["last_updated"].ToString()))
|
||||||
};
|
};
|
||||||
categoryModel.SyndicationCount = await dbc.ExecuteScalarAsync<int>($"SELECT COUNT(*) FROM syndication WHERE category_id=@CatId", new { CatId = categoryModel.Id });
|
categoryModel.Syndications = await GetSyndicationsAsync(new []{ categoryModel.Id });
|
||||||
|
//categoryModel.SyndicationCount = await dbc.ExecuteScalarAsync<int>($"SELECT COUNT(*) FROM syndication WHERE category_id=@CatId", new { CatId = categoryModel.Id });
|
||||||
categories.Add(categoryModel);
|
categories.Add(categoryModel);
|
||||||
}
|
}
|
||||||
return categories;
|
return categories;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using ToolQit;
|
using ToolQit;
|
||||||
using ToolQit.Extensions;
|
using ToolQit.Extensions;
|
||||||
|
|
||||||
|
@ -26,6 +27,6 @@ namespace SharpRss.Models
|
||||||
}
|
}
|
||||||
public string Icon { get; set; } = string.Empty;
|
public string Icon { get; set; } = string.Empty;
|
||||||
public DateTimeOffset LastUpdated { get; set; } = DateTimeOffset.Now;
|
public DateTimeOffset LastUpdated { get; set; } = DateTimeOffset.Now;
|
||||||
public int SyndicationCount { get; set; }
|
public HashSet<SyndicationModel> Syndications { get; set; } = new HashSet<SyndicationModel>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,10 @@ namespace WebSharpRSS.Models
|
||||||
CategoryModel = categoryModel;
|
CategoryModel = categoryModel;
|
||||||
Title = categoryModel.Name;
|
Title = categoryModel.Name;
|
||||||
Icon = categoryModel.Icon == string.Empty ? Icons.Material.Filled.RssFeed : categoryModel.Icon;
|
Icon = categoryModel.Icon == string.Empty ? Icons.Material.Filled.RssFeed : categoryModel.Icon;
|
||||||
HasChildren = CategoryModel.SyndicationCount > 0;
|
HasChildren = CategoryModel.Syndications.Count > 0;
|
||||||
}
|
if (HasChildren)
|
||||||
|
CategoryModel.Syndications.Select(x => x.ItemCount).ToList().ForEach(i => TotalItems += i);
|
||||||
|
}
|
||||||
|
|
||||||
public TreeItemData(SyndicationModel syndicationModel)
|
public TreeItemData(SyndicationModel syndicationModel)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,8 +1,21 @@
|
||||||
@using WebSharpRSS.Models
|
@using WebSharpRSS.Models
|
||||||
|
@using ToolQit.Extensions
|
||||||
|
|
||||||
<MudDialog>
|
<MudDialog>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<ItemView FeedItem="Data"/>
|
<div style="justify-self: start;" class="d-flex align-center">
|
||||||
|
@if (Data?.SyndicationParent.ImageUrl != null)
|
||||||
|
{
|
||||||
|
<MudImage Src="@Data.SyndicationParent.ImageUrl" ObjectFit="ObjectFit.Contain" Width="32" Height="32"/>
|
||||||
|
}
|
||||||
|
<div class="d-inline px-3 align-center" style="font-size: 30px;">
|
||||||
|
@((MarkupString)(Data?.Title ?? "This item doesn't contains a title!"))
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<MudDivider DividerType="DividerType.FullWidth" Light="false" Class="my-2"/>
|
||||||
|
<div style="font-size: 20px">
|
||||||
|
@((MarkupString)((Data?.Content == null || Data.Content.IsNullEmptyWhiteSpace() ? Data?.Description : Data.Content) ?? "This item doesn't contain any content!"))
|
||||||
|
</div>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</MudDialog>
|
</MudDialog>
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
<MudTreeViewItem @bind-Expanded="@context.IsExpanded" Value="@context" Items="@context.Children" CanExpand="@context.HasChildren" @onclick="ItemClicked">
|
<MudTreeViewItem @bind-Expanded="@context.IsExpanded" Value="@context" Items="@context.Children" CanExpand="@context.HasChildren" @onclick="ItemClicked">
|
||||||
<Content>
|
<Content>
|
||||||
<div style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%">
|
<div style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%">
|
||||||
<div style="justify-self: start;" class="d-flex align-center">
|
<div class="d-flex align-center">
|
||||||
<MudTreeViewItemToggleButton ExpandedChanged="@(() => ExpandedChanged(context))" Loading="@context.Loading" Visible="@context.HasChildren" LoadingIconColor="Color.Info" />
|
<MudTreeViewItemToggleButton ExpandedChanged="@(() => ExpandedChanged(context))" Loading="@context.Loading" Visible="@context.HasChildren" LoadingIconColor="Color.Info" />
|
||||||
@if (context.FaviconUrl == null && context.Icon != null)
|
@if (context.FaviconUrl == null && context.Icon != null)
|
||||||
{
|
{
|
||||||
|
@ -26,6 +26,7 @@
|
||||||
}
|
}
|
||||||
<MudText Class="ml-2">@context.Title</MudText>
|
<MudText Class="ml-2">@context.Title</MudText>
|
||||||
</div>
|
</div>
|
||||||
|
<MudText Class="d-inline-flex align-self-end" Color="Color.Secondary" Typo="Typo.overline">@context.TotalItems</MudText>
|
||||||
</div>
|
</div>
|
||||||
</Content>
|
</Content>
|
||||||
</MudTreeViewItem>
|
</MudTreeViewItem>
|
||||||
|
|
|
@ -14,20 +14,25 @@
|
||||||
<div style="justify-self: start;" class="d-flex align-center">
|
<div style="justify-self: start;" class="d-flex align-center">
|
||||||
@if (feedItemData.SyndicationParent.Category != null && !feedItemData.SyndicationParent.Category.Icon.IsNullEmptyWhiteSpace())
|
@if (feedItemData.SyndicationParent.Category != null && !feedItemData.SyndicationParent.Category.Icon.IsNullEmptyWhiteSpace())
|
||||||
{
|
{
|
||||||
<MudIcon Icon="@feedItemData.SyndicationParent.Category.Icon" Style="@($"color:{feedItemData.SyndicationParent.Category.HexColor}")"/>
|
<MudTooltip Text="@feedItemData.SyndicationParent.Category.Name">
|
||||||
|
<MudIcon Icon="@feedItemData.SyndicationParent.Category.Icon" Class="mr-1" Style="@($"color:{feedItemData.SyndicationParent.Category.HexColor}")"/>
|
||||||
|
</MudTooltip>
|
||||||
}
|
}
|
||||||
@if (feedItemData.SyndicationParent.ImageUrl != null)
|
@if (feedItemData.SyndicationParent.ImageUrl != null)
|
||||||
{
|
{
|
||||||
<MudImage Src="@feedItemData.SyndicationParent.ImageUrl" ObjectFit="ObjectFit.Contain" Width="32" Height="32"/>
|
<MudTooltip Text="@feedItemData.SyndicationParent.Title">
|
||||||
|
<MudImage Src="@feedItemData.SyndicationParent.ImageUrl" ObjectFit="ObjectFit.Contain" Width="20" Height="20"/>
|
||||||
|
</MudTooltip>
|
||||||
}
|
}
|
||||||
<div class="d-inline pa-2 align-center" style="font-size: 16px;">
|
<div class="d-inline ma-2 align-center" style="font-size: 20px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 1; line-clamp: 1; -webkit-box-orient: vertical;">
|
||||||
@if (feedItemData.Title != null)
|
@if (feedItemData.Title != null)
|
||||||
{
|
{
|
||||||
@((MarkupString)feedItemData.Title)
|
@((MarkupString)feedItemData.Title)
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
<MudText Typo="Typo.subtitle2" Color="Color.Secondary"> - @feedItemData.SyndicationParent.Title</MudText>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div style="overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; line-clamp:2; -webkit-box-orient: vertical;">
|
||||||
@if (feedItemData.Description != null && !feedItemData.Description.IsNullEmptyWhiteSpace())
|
@if (feedItemData.Description != null && !feedItemData.Description.IsNullEmptyWhiteSpace())
|
||||||
{
|
{
|
||||||
@((MarkupString)feedItemData.Description)
|
@((MarkupString)feedItemData.Description)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user