2013-02-24 00:29:22 +03:00
|
|
|
using System;
|
2013-05-07 05:32:43 +03:00
|
|
|
using System.Collections.Generic;
|
2013-02-24 00:29:22 +03:00
|
|
|
using System.Linq;
|
2013-05-11 01:33:04 +03:00
|
|
|
using Marr.Data.QGen;
|
2013-02-24 00:29:22 +03:00
|
|
|
using NzbDrone.Core.Datastore;
|
2013-09-11 09:33:47 +03:00
|
|
|
using NzbDrone.Core.Messaging;
|
2013-02-24 00:29:22 +03:00
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.History
|
|
|
|
{
|
|
|
|
public interface IHistoryRepository : IBasicRepository<History>
|
|
|
|
{
|
|
|
|
void Trim();
|
2013-05-14 17:36:23 +03:00
|
|
|
List<QualityModel> GetEpisodeHistory(int episodeId);
|
2013-02-24 00:29:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public class HistoryRepository : BasicRepository<History>, IHistoryRepository
|
|
|
|
{
|
2013-05-06 00:24:33 +03:00
|
|
|
public HistoryRepository(IDatabase database, IMessageAggregator messageAggregator)
|
|
|
|
: base(database, messageAggregator)
|
2013-02-24 00:29:22 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Trim()
|
|
|
|
{
|
2013-06-09 23:50:57 +03:00
|
|
|
var cutoff = DateTime.UtcNow.AddDays(-30).Date;
|
2013-03-27 06:44:52 +03:00
|
|
|
Delete(c=> c.Date < cutoff);
|
2013-02-24 00:29:22 +03:00
|
|
|
}
|
|
|
|
|
2013-05-14 17:36:23 +03:00
|
|
|
public List<QualityModel> GetEpisodeHistory(int episodeId)
|
2013-02-24 00:29:22 +03:00
|
|
|
{
|
2013-05-14 08:40:06 +03:00
|
|
|
var history = Query.Where(c => c.EpisodeId == episodeId);
|
2013-02-24 00:29:22 +03:00
|
|
|
|
2013-05-14 08:40:06 +03:00
|
|
|
return history.Select(h => h.Quality).ToList();
|
2013-02-24 00:29:22 +03:00
|
|
|
}
|
2013-05-07 05:32:43 +03:00
|
|
|
|
2013-06-05 03:49:53 +03:00
|
|
|
public override PagingSpec<History> GetPaged(PagingSpec<History> pagingSpec)
|
2013-05-11 01:33:04 +03:00
|
|
|
{
|
|
|
|
var pagingQuery = Query.Join<History, Series>(JoinType.Inner, h => h.Series, (h, s) => h.SeriesId == s.Id)
|
|
|
|
.Join<History, Episode>(JoinType.Inner, h => h.Episode, (h, e) => h.EpisodeId == e.Id)
|
|
|
|
.OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection())
|
|
|
|
.Skip(pagingSpec.PagingOffset())
|
|
|
|
.Take(pagingSpec.PageSize);
|
|
|
|
|
|
|
|
pagingSpec.Records = pagingQuery.ToList();
|
|
|
|
|
|
|
|
//TODO: Use the same query for count and records
|
|
|
|
pagingSpec.TotalRecords = Count();
|
|
|
|
|
|
|
|
return pagingSpec;
|
|
|
|
}
|
2013-02-24 00:29:22 +03:00
|
|
|
}
|
|
|
|
}
|