Need db reworking for usage new syndication system

This commit is contained in:
Max 2023-05-31 20:27:13 +02:00
parent ce90818e3d
commit 924e174240

View File

@ -4,6 +4,7 @@ using System.Data;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Argotic.Syndication;
using Dapper;
using Microsoft.Data.Sqlite;
using Serilog;
@ -160,8 +161,36 @@ namespace SharpRss
await cmd.ExecuteNonQueryAsync();
}
await transaction.CommitAsync();
await FetchFeedItemsAsync(feedModels.Select(x => x.Url).ToArray());
return resultModel;
}
public static async Task FetchFeedItemsAsync(string[]? feedUrls = null)
{
await using SqliteConnection dbc = new SqliteConnection(ConnectionString);
dbc.Open();
HashSet<FeedModel> dbFeeds = new HashSet<FeedModel>();
string query = $"SELECT * FROM {FeedTable}";
if (feedUrls != null)
{
List<string>? feedUrlsFormatted = feedUrls.Select(s => $"'{s}'").ToList();
query = $"SELECT * FROM {FeedTable} WHERE url IN(({string.Join(", ", feedUrlsFormatted)}))";
}
await using SqliteCommand fetchCmd = new SqliteCommand(query, dbc);
await using SqliteDataReader reader = await fetchCmd.ExecuteReaderAsync();
while (reader.Read())
{
dbFeeds.Add(await ReaderToFeedModel(reader));
}
HashSet<FeedItemModel> feedItems = new HashSet<FeedItemModel>();
foreach (var dbFeed in dbFeeds)
{
GenericSyndicationFeed syndication = new GenericSyndicationFeed();
syndication.Load(dbFeed.OriginalDocument);
}
//TODO: Rewrite some stuff...
}
public static async Task<bool> RemoveFeedAsync(FeedModel feedModel)
{
bool result = false;