move filtering of protocols to controller
This commit is contained in:
parent
2b7f63e76b
commit
c24db3bf9a
|
@ -1,6 +1,5 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using NzbDrone.Core.Datastore;
|
using NzbDrone.Core.Datastore;
|
||||||
using NzbDrone.Core.Indexers;
|
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
using NzbDrone.Core.Tv;
|
using NzbDrone.Core.Tv;
|
||||||
|
|
||||||
|
@ -12,7 +11,6 @@ namespace NzbDrone.Core.Blocklisting
|
||||||
List<Blocklist> BlocklistedByTorrentInfoHash(int seriesId, string torrentInfoHash);
|
List<Blocklist> BlocklistedByTorrentInfoHash(int seriesId, string torrentInfoHash);
|
||||||
List<Blocklist> BlocklistedBySeries(int seriesId);
|
List<Blocklist> BlocklistedBySeries(int seriesId);
|
||||||
void DeleteForSeriesIds(List<int> seriesIds);
|
void DeleteForSeriesIds(List<int> seriesIds);
|
||||||
PagingSpec<Blocklist> GetPaged(PagingSpec<Blocklist> pagingSpec, DownloadProtocol[] protocols);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BlocklistRepository : BasicRepository<Blocklist>, IBlocklistRepository
|
public class BlocklistRepository : BasicRepository<Blocklist>, IBlocklistRepository
|
||||||
|
@ -42,26 +40,21 @@ namespace NzbDrone.Core.Blocklisting
|
||||||
Delete(x => seriesIds.Contains(x.SeriesId));
|
Delete(x => seriesIds.Contains(x.SeriesId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public PagingSpec<Blocklist> GetPaged(PagingSpec<Blocklist> pagingSpec, DownloadProtocol[] protocols)
|
public override PagingSpec<Blocklist> GetPaged(PagingSpec<Blocklist> pagingSpec)
|
||||||
{
|
{
|
||||||
pagingSpec.Records = GetPagedRecords(PagedBuilder(protocols), pagingSpec, PagedQuery);
|
pagingSpec.Records = GetPagedRecords(PagedBuilder(), pagingSpec, PagedQuery);
|
||||||
|
|
||||||
var countTemplate = $"SELECT COUNT(*) FROM (SELECT /**select**/ FROM \"{TableMapping.Mapper.TableNameMapping(typeof(Blocklist))}\" /**join**/ /**innerjoin**/ /**leftjoin**/ /**where**/ /**groupby**/ /**having**/) AS \"Inner\"";
|
var countTemplate = $"SELECT COUNT(*) FROM (SELECT /**select**/ FROM \"{TableMapping.Mapper.TableNameMapping(typeof(Blocklist))}\" /**join**/ /**innerjoin**/ /**leftjoin**/ /**where**/ /**groupby**/ /**having**/) AS \"Inner\"";
|
||||||
pagingSpec.TotalRecords = GetPagedRecordCount(PagedBuilder(protocols).Select(typeof(Blocklist)), pagingSpec, countTemplate);
|
pagingSpec.TotalRecords = GetPagedRecordCount(PagedBuilder().Select(typeof(Blocklist)), pagingSpec, countTemplate);
|
||||||
|
|
||||||
return pagingSpec;
|
return pagingSpec;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SqlBuilder PagedBuilder(DownloadProtocol[] protocols)
|
protected override SqlBuilder PagedBuilder()
|
||||||
{
|
{
|
||||||
var builder = Builder()
|
var builder = Builder()
|
||||||
.Join<Blocklist, Series>((b, m) => b.SeriesId == m.Id);
|
.Join<Blocklist, Series>((b, m) => b.SeriesId == m.Id);
|
||||||
|
|
||||||
if (protocols is { Length: > 0 })
|
|
||||||
{
|
|
||||||
builder.Where($"({BuildProtocolWhereClause(protocols)})");
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,17 +64,5 @@ namespace NzbDrone.Core.Blocklisting
|
||||||
blocklist.Series = series;
|
blocklist.Series = series;
|
||||||
return blocklist;
|
return blocklist;
|
||||||
});
|
});
|
||||||
|
|
||||||
private string BuildProtocolWhereClause(DownloadProtocol[] protocols)
|
|
||||||
{
|
|
||||||
var clauses = new List<string>();
|
|
||||||
|
|
||||||
foreach (var protocol in protocols)
|
|
||||||
{
|
|
||||||
clauses.Add($"\"{TableMapping.Mapper.TableNameMapping(typeof(Blocklist))}\".\"Protocol\" = {(int)protocol}");
|
|
||||||
}
|
|
||||||
|
|
||||||
return $"({string.Join(" OR ", clauses)})";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace NzbDrone.Core.Blocklisting
|
||||||
{
|
{
|
||||||
bool Blocklisted(int seriesId, ReleaseInfo release);
|
bool Blocklisted(int seriesId, ReleaseInfo release);
|
||||||
bool BlocklistedTorrentHash(int seriesId, string hash);
|
bool BlocklistedTorrentHash(int seriesId, string hash);
|
||||||
PagingSpec<Blocklist> Paged(PagingSpec<Blocklist> pagingSpec, DownloadProtocol[] protocols);
|
PagingSpec<Blocklist> Paged(PagingSpec<Blocklist> pagingSpec);
|
||||||
void Block(RemoteEpisode remoteEpisode, string message);
|
void Block(RemoteEpisode remoteEpisode, string message);
|
||||||
void Delete(int id);
|
void Delete(int id);
|
||||||
void Delete(List<int> ids);
|
void Delete(List<int> ids);
|
||||||
|
@ -66,9 +66,9 @@ namespace NzbDrone.Core.Blocklisting
|
||||||
b.TorrentInfoHash.Equals(hash, StringComparison.InvariantCultureIgnoreCase));
|
b.TorrentInfoHash.Equals(hash, StringComparison.InvariantCultureIgnoreCase));
|
||||||
}
|
}
|
||||||
|
|
||||||
public PagingSpec<Blocklist> Paged(PagingSpec<Blocklist> pagingSpec, DownloadProtocol[] protocols)
|
public PagingSpec<Blocklist> Paged(PagingSpec<Blocklist> pagingSpec)
|
||||||
{
|
{
|
||||||
return _blocklistRepository.GetPaged(pagingSpec, protocols);
|
return _blocklistRepository.GetPaged(pagingSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Block(RemoteEpisode remoteEpisode, string message)
|
public void Block(RemoteEpisode remoteEpisode, string message)
|
||||||
|
|
|
@ -30,12 +30,17 @@ namespace Sonarr.Api.V3.Blocklist
|
||||||
var pagingResource = new PagingResource<BlocklistResource>(paging);
|
var pagingResource = new PagingResource<BlocklistResource>(paging);
|
||||||
var pagingSpec = pagingResource.MapToPagingSpec<BlocklistResource, NzbDrone.Core.Blocklisting.Blocklist>("date", SortDirection.Descending);
|
var pagingSpec = pagingResource.MapToPagingSpec<BlocklistResource, NzbDrone.Core.Blocklisting.Blocklist>("date", SortDirection.Descending);
|
||||||
|
|
||||||
if (seriesIds != null && seriesIds.Any())
|
if (seriesIds?.Any() == true)
|
||||||
{
|
{
|
||||||
pagingSpec.FilterExpressions.Add(b => seriesIds.Contains(b.SeriesId));
|
pagingSpec.FilterExpressions.Add(b => seriesIds.Contains(b.SeriesId));
|
||||||
}
|
}
|
||||||
|
|
||||||
return pagingSpec.ApplyToPage(b => _blocklistService.Paged(pagingSpec, protocols), b => BlocklistResourceMapper.MapToResource(b, _formatCalculator));
|
if (protocols?.Any() == true)
|
||||||
|
{
|
||||||
|
pagingSpec.FilterExpressions.Add(b => protocols.Contains(b.Protocol));
|
||||||
|
}
|
||||||
|
|
||||||
|
return pagingSpec.ApplyToPage(b => _blocklistService.Paged(pagingSpec), b => BlocklistResourceMapper.MapToResource(b, _formatCalculator));
|
||||||
}
|
}
|
||||||
|
|
||||||
[RestDeleteById]
|
[RestDeleteById]
|
||||||
|
|
Loading…
Reference in New Issue