mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
Tissue service will sanitize the existign database of ingested torrents by matching existing titles with new banned word lists. Now with added kleenex
45 lines
1.6 KiB
C#
45 lines
1.6 KiB
C#
namespace Tissue.Features.DataProcessing;
|
|
|
|
public class DapperDataStorage(PostgresConfiguration configuration, ILogger<DapperDataStorage> logger) : IDataStorage
|
|
{
|
|
public async Task<IReadOnlyCollection<Torrent>?> GetAllTorrents(CancellationToken cancellationToken = default)
|
|
{
|
|
const string GetAllTorrentsSql = "SELECT * FROM torrents";
|
|
|
|
try
|
|
{
|
|
await using var connection = await CreateAndOpenConnection(cancellationToken);
|
|
var torrents = await connection.QueryAsync<Torrent>(GetAllTorrentsSql);
|
|
|
|
return torrents.ToList();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
logger.LogError(e, "Error while torrents from database");
|
|
return new List<Torrent>();
|
|
}
|
|
}
|
|
|
|
public async Task DeleteTorrentsByInfoHashes(IReadOnlyCollection<string> infoHashes, CancellationToken cancellationToken = default)
|
|
{
|
|
const string deleteTorrentsSql = "DELETE FROM torrents WHERE \"infoHash\" = ANY(@infoHashes)";
|
|
|
|
try
|
|
{
|
|
await using var connection = await CreateAndOpenConnection(cancellationToken);
|
|
await connection.ExecuteAsync(deleteTorrentsSql, new { infoHashes });
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
logger.LogError(e, "Error while deleting torrents from database");
|
|
}
|
|
}
|
|
|
|
private async Task<NpgsqlConnection> CreateAndOpenConnection(CancellationToken cancellationToken = default)
|
|
{
|
|
var connection = new NpgsqlConnection(configuration.StorageConnectionString);
|
|
await connection.OpenAsync(cancellationToken);
|
|
return connection;
|
|
}
|
|
}
|