2013-02-24 00:29:22 +03:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.History
|
|
|
|
{
|
|
|
|
public interface IHistoryRepository : IBasicRepository<History>
|
|
|
|
{
|
|
|
|
void Trim();
|
|
|
|
QualityModel GetBestQualityInHistory(int seriesId, int seasonNumber, int episodeNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
public class HistoryRepository : BasicRepository<History>, IHistoryRepository
|
|
|
|
{
|
|
|
|
public HistoryRepository(IObjectDatabase objectDatabase)
|
|
|
|
: base(objectDatabase)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Trim()
|
|
|
|
{
|
2013-02-26 06:58:57 +03:00
|
|
|
var oldIds = Queryable.Where(c => c.Date < DateTime.Now.AddDays(-30).Date).Select(c => c.Id);
|
2013-02-24 00:29:22 +03:00
|
|
|
DeleteMany(oldIds);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public QualityModel GetBestQualityInHistory(int seriesId, int seasonNumber, int episodeNumber)
|
|
|
|
{
|
2013-02-26 06:58:57 +03:00
|
|
|
var history = Queryable.OrderByDescending(c => c.Quality).FirstOrDefault(c => c.Episode.Series.Id == seriesId && c.Episode.SeasonNumber == seasonNumber &&
|
2013-02-24 00:29:22 +03:00
|
|
|
c.Episode.EpisodeNumber == episodeNumber);
|
|
|
|
|
|
|
|
if (history != null)
|
|
|
|
{
|
|
|
|
return history.Quality;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|