@ -1,6 +1,7 @@
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Linq.Expressions ;
using Marr.Data.QGen ;
using NzbDrone.Core.Datastore ;
using NzbDrone.Core.Messaging.Events ;
@ -11,8 +12,7 @@ namespace NzbDrone.Core.History
public interface IHistoryRepository : IBasicRepository < History >
{
void Trim ( ) ;
List < QualityModel > GetEpisodeHistory ( int episodeId ) ;
List < History > ByEpisode ( int episodeId ) ;
List < QualityModel > GetBestQualityInHistory ( int episodeId ) ;
}
public class HistoryRepository : BasicRepository < History > , IHistoryRepository
@ -31,32 +31,29 @@ namespace NzbDrone.Core.History
Delete ( c = > c . Date < cutoff ) ;
}
public List < QualityModel > Get Episode History( int episodeId )
public List < QualityModel > Get BestQualityIn History( int episodeId )
{
var history = Query . Where ( c = > c . EpisodeId = = episodeId ) ;
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 )
p rivate SortBuilder < History > GetPaged Query ( 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 )
. Where ( pagingSpec . FilterExpression )
. 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 ;
}
}
}