|
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using Marr.Data.QGen;
|
|
|
|
using Marr.Data.QGen;
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
using NzbDrone.Core.Messaging;
|
|
|
|
|
|
|
|
using NzbDrone.Core.Messaging.Events;
|
|
|
|
using NzbDrone.Core.Messaging.Events;
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
|
|
|
|
|
|
@ -13,13 +12,18 @@ namespace NzbDrone.Core.History
|
|
|
|
{
|
|
|
|
{
|
|
|
|
void Trim();
|
|
|
|
void Trim();
|
|
|
|
List<QualityModel> GetEpisodeHistory(int episodeId);
|
|
|
|
List<QualityModel> GetEpisodeHistory(int episodeId);
|
|
|
|
|
|
|
|
void CleanupOrphanedBySeries();
|
|
|
|
|
|
|
|
void CleanupOrphanedByEpisode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class HistoryRepository : BasicRepository<History>, IHistoryRepository
|
|
|
|
public class HistoryRepository : BasicRepository<History>, IHistoryRepository
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
private readonly IDatabase _database;
|
|
|
|
|
|
|
|
|
|
|
|
public HistoryRepository(IDatabase database, IEventAggregator eventAggregator)
|
|
|
|
public HistoryRepository(IDatabase database, IEventAggregator eventAggregator)
|
|
|
|
: base(database, eventAggregator)
|
|
|
|
: base(database, eventAggregator)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
_database = database;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Trim()
|
|
|
|
public void Trim()
|
|
|
@ -35,6 +39,30 @@ namespace NzbDrone.Core.History
|
|
|
|
return history.Select(h => h.Quality).ToList();
|
|
|
|
return history.Select(h => h.Quality).ToList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void CleanupOrphanedBySeries()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var mapper = _database.GetDataMapper();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapper.ExecuteNonQuery(@"DELETE FROM History
|
|
|
|
|
|
|
|
WHERE Id IN (
|
|
|
|
|
|
|
|
SELECT History.Id FROM History
|
|
|
|
|
|
|
|
LEFT OUTER JOIN Series
|
|
|
|
|
|
|
|
ON History.SeriesId = Series.Id
|
|
|
|
|
|
|
|
WHERE Series.Id IS NULL)");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void CleanupOrphanedByEpisode()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var mapper = _database.GetDataMapper();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapper.ExecuteNonQuery(@"DELETE FROM History
|
|
|
|
|
|
|
|
WHERE Id IN (
|
|
|
|
|
|
|
|
SELECT History.Id FROM History
|
|
|
|
|
|
|
|
LEFT OUTER JOIN Episodes
|
|
|
|
|
|
|
|
ON History.EpisodeId = Episodes.Id
|
|
|
|
|
|
|
|
WHERE Episodes.Id IS NULL)");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override PagingSpec<History> GetPaged(PagingSpec<History> pagingSpec)
|
|
|
|
public override PagingSpec<History> GetPaged(PagingSpec<History> pagingSpec)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var pagingQuery = Query.Join<History, Series>(JoinType.Inner, h => h.Series, (h, s) => h.SeriesId == s.Id)
|
|
|
|
var pagingQuery = Query.Join<History, Series>(JoinType.Inner, h => h.Series, (h, s) => h.SeriesId == s.Id)
|
|
|
|