|
|
@ -1,6 +1,7 @@
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
using Marr.Data.QGen;
|
|
|
|
using Marr.Data.QGen;
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
using NzbDrone.Core.Messaging.Events;
|
|
|
|
using NzbDrone.Core.Messaging.Events;
|
|
|
@ -11,8 +12,7 @@ namespace NzbDrone.Core.History
|
|
|
|
public interface IHistoryRepository : IBasicRepository<History>
|
|
|
|
public interface IHistoryRepository : IBasicRepository<History>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
void Trim();
|
|
|
|
void Trim();
|
|
|
|
List<QualityModel> GetEpisodeHistory(int episodeId);
|
|
|
|
List<QualityModel> GetBestQualityInHistory(int episodeId);
|
|
|
|
List<History> ByEpisode(int episodeId);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class HistoryRepository : BasicRepository<History>, IHistoryRepository
|
|
|
|
public class HistoryRepository : BasicRepository<History>, IHistoryRepository
|
|
|
@ -31,32 +31,29 @@ namespace NzbDrone.Core.History
|
|
|
|
Delete(c=> c.Date < cutoff);
|
|
|
|
Delete(c=> c.Date < cutoff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<QualityModel> GetEpisodeHistory(int episodeId)
|
|
|
|
public List<QualityModel> GetBestQualityInHistory(int episodeId)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var history = Query.Where(c => c.EpisodeId == episodeId);
|
|
|
|
var history = Query.Where(c => c.EpisodeId == episodeId);
|
|
|
|
|
|
|
|
|
|
|
|
return history.Select(h => h.Quality).ToList();
|
|
|
|
return history.Select(h => h.Quality).ToList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<History> ByEpisode(int episodeId)
|
|
|
|
public override PagingSpec<History> GetPaged(PagingSpec<History> pagingSpec)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Query.Where(h => h.EpisodeId == episodeId).ToList();
|
|
|
|
pagingSpec.Records = GetPagedQuery(pagingSpec).ToList();
|
|
|
|
|
|
|
|
pagingSpec.TotalRecords = GetPagedQuery(pagingSpec).GetRowCount();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return pagingSpec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override PagingSpec<History> GetPaged(PagingSpec<History> pagingSpec)
|
|
|
|
private SortBuilder<History> GetPagedQuery(PagingSpec<History> pagingSpec)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var pagingQuery = Query.Join<History, Series>(JoinType.Inner, h => h.Series, (h, s) => h.SeriesId == s.Id)
|
|
|
|
return 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)
|
|
|
|
.Join<History, Episode>(JoinType.Inner, h => h.Episode, (h, e) => h.EpisodeId == e.Id)
|
|
|
|
|
|
|
|
.Where(pagingSpec.FilterExpression)
|
|
|
|
.OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection())
|
|
|
|
.OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection())
|
|
|
|
.Skip(pagingSpec.PagingOffset())
|
|
|
|
.Skip(pagingSpec.PagingOffset())
|
|
|
|
.Take(pagingSpec.PageSize);
|
|
|
|
.Take(pagingSpec.PageSize);
|
|
|
|
|
|
|
|
|
|
|
|
pagingSpec.Records = pagingQuery.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: Use the same query for count and records
|
|
|
|
|
|
|
|
pagingSpec.TotalRecords = Count();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return pagingSpec;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|