mirror of
https://github.com/Sonarr/Sonarr
synced 2024-12-25 17:27:18 +00:00
More better joins, some minor MDM changes for paging
This commit is contained in:
parent
32431540c5
commit
3602822572
7 changed files with 20 additions and 9 deletions
|
@ -365,7 +365,7 @@ namespace Marr.Data.QGen
|
|||
|
||||
public virtual SortBuilder<T> Where(Expression<Func<T, bool>> filterExpression)
|
||||
{
|
||||
_whereBuilder = new WhereBuilder<T>(_db.Command, _dialect, filterExpression, _tables, false, true);
|
||||
_whereBuilder = new WhereBuilder<T>(_db.Command, _dialect, filterExpression, _tables, _useAltName, true);
|
||||
return SortBuilder;
|
||||
}
|
||||
|
||||
|
|
|
@ -217,7 +217,12 @@ namespace Marr.Data.QGen
|
|||
}
|
||||
|
||||
string columnName = DataHelper.GetColumnName(sort.DeclaringType, sort.PropertyName, useAltName);
|
||||
sb.Append(_dialect.CreateToken(string.Format("{0}.{1}", table.Alias, columnName)));
|
||||
|
||||
if (!_useAltName)
|
||||
sb.Append(_dialect.CreateToken(string.Format("{0}.{1}", table.Alias, columnName)));
|
||||
|
||||
else
|
||||
sb.Append(_dialect.CreateToken(string.Format("{0}", columnName)));
|
||||
|
||||
if (sort.Direction == SortDirection.Desc)
|
||||
sb.Append(" DESC");
|
||||
|
|
|
@ -182,7 +182,12 @@ namespace Marr.Data.QGen
|
|||
}
|
||||
|
||||
string columnName = DataHelper.GetColumnName(declaringType, member.Name, _useAltName);
|
||||
return _dialect.CreateToken(string.Format("{0}.{1}", table.Alias, columnName));
|
||||
|
||||
if (!_useAltName)
|
||||
return _dialect.CreateToken(string.Format("{0}.{1}", table.Alias, columnName));
|
||||
|
||||
else
|
||||
return _dialect.CreateToken(string.Format("{0}", columnName));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -23,6 +23,7 @@ namespace NzbDrone.Core.Datastore
|
|||
return mapBuilder.Table.MapTable(tableName)
|
||||
.Columns
|
||||
.AutoMapPropertiesWhere(IsMappableProperty)
|
||||
.PrefixAltNames(String.Format("{0}_", typeof(T).Name))
|
||||
.For(c => c.Id)
|
||||
.SetPrimaryKey()
|
||||
.SetReturnValue()
|
||||
|
|
|
@ -52,7 +52,8 @@ namespace NzbDrone.Core.Datastore
|
|||
Mapper.Entity<Season>().RegisterModel("Seasons");
|
||||
|
||||
Mapper.Entity<Episode>().RegisterModel("Episodes")
|
||||
.Ignore(e => e.SeriesTitle);
|
||||
.Ignore(e => e.SeriesTitle)
|
||||
.Relationships.AutoMapICollectionOrComplexProperties();
|
||||
|
||||
Mapper.Entity<EpisodeFile>().RegisterModel("EpisodeFiles");
|
||||
|
||||
|
|
|
@ -75,14 +75,15 @@ namespace NzbDrone.Core.Tv
|
|||
startingSeasonNumber = 0;
|
||||
}
|
||||
|
||||
pagingSpec.Records = Query.Join<Episode, Series>(JoinType.Inner, e => e.Series, (e, s) => e.SeriesId == s.Id)
|
||||
var pagingQuery = Query.Join<Episode, Series>(JoinType.Inner, e => e.Series, (e, s) => e.SeriesId == s.Id)
|
||||
.Where(e => e.EpisodeFileId == 0)
|
||||
.AndWhere(e => e.SeasonNumber >= startingSeasonNumber)
|
||||
.AndWhere(e => e.AirDate <= currentTime)
|
||||
.OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection())
|
||||
.Skip(pagingSpec.PagingOffset())
|
||||
.Take(pagingSpec.PageSize)
|
||||
.ToList();
|
||||
.Take(pagingSpec.PageSize);
|
||||
|
||||
pagingSpec.Records = pagingQuery.ToList();
|
||||
|
||||
//TODO: Use the same query for count and records
|
||||
pagingSpec.TotalRecords = Query.Where(e => e.EpisodeFileId == 0 && e.SeasonNumber >= startingSeasonNumber && e.AirDate <= currentTime).Count();
|
||||
|
|
|
@ -99,8 +99,6 @@ namespace NzbDrone.Core.Tv
|
|||
{
|
||||
var episodeResult = _episodeRepository.EpisodesWithoutFiles(pagingSpec, includeSpecials);
|
||||
|
||||
episodeResult.Records = LinkSeriesToEpisodes(episodeResult.Records);
|
||||
|
||||
return episodeResult;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue