mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-04 22:24:14 -04:00
Handle mixed nulls for sorts and pagination
This commit is contained in:
parent
ef3e4dc39b
commit
b62af8d2ae
@ -184,10 +184,16 @@ namespace Kyoo.Abstractions.Models
|
|||||||
Fonts = await transcoder.ListFonts(ep),
|
Fonts = await transcoder.ListFonts(ep),
|
||||||
PreviousEpisode = ep.Show.IsMovie
|
PreviousEpisode = ep.Show.IsMovie
|
||||||
? null
|
? null
|
||||||
: (await library.GetAll<Episode>(limit: new Pagination(1, ep.ID, true))).FirstOrDefault(),
|
: (await library.GetAll<Episode>(
|
||||||
|
where: x => x.ShowID == ep.ShowID,
|
||||||
|
limit: new Pagination(1, ep.ID, true)
|
||||||
|
)).FirstOrDefault(),
|
||||||
NextEpisode = ep.Show.IsMovie
|
NextEpisode = ep.Show.IsMovie
|
||||||
? null
|
? null
|
||||||
: (await library.GetAll<Episode>(limit: new Pagination(1, ep.ID))).FirstOrDefault(),
|
: (await library.GetAll<Episode>(
|
||||||
|
where: x => x.ShowID == ep.ShowID,
|
||||||
|
limit: new Pagination(1, ep.ID)
|
||||||
|
)).FirstOrDefault(),
|
||||||
Chapters = await _GetChapters(ep, fs),
|
Chapters = await _GetChapters(ep, fs),
|
||||||
IsMovie = ep.Show.IsMovie
|
IsMovie = ep.Show.IsMovie
|
||||||
};
|
};
|
||||||
|
@ -168,6 +168,14 @@ namespace Kyoo.Core.Controllers
|
|||||||
foreach ((string key, bool desc) in sorts)
|
foreach ((string key, bool desc) in sorts)
|
||||||
{
|
{
|
||||||
BinaryExpression compare = null;
|
BinaryExpression compare = null;
|
||||||
|
PropertyInfo property = typeof(T).GetProperty(key);
|
||||||
|
|
||||||
|
// Comparing a value with null always return false so we short opt < > comparisons with null.
|
||||||
|
if (property.GetValue(reference) == null)
|
||||||
|
{
|
||||||
|
previousSteps.Add(new(key, desc));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Create all the equality statements for previous sorts.
|
// Create all the equality statements for previous sorts.
|
||||||
foreach ((string pKey, bool pDesc) in previousSteps)
|
foreach ((string pKey, bool pDesc) in previousSteps)
|
||||||
@ -186,6 +194,16 @@ namespace Kyoo.Core.Controllers
|
|||||||
MemberExpression xkey = Expression.Property(x, key);
|
MemberExpression xkey = Expression.Property(x, key);
|
||||||
MemberExpression rkey = Expression.Property(referenceC, key);
|
MemberExpression rkey = Expression.Property(referenceC, key);
|
||||||
BinaryExpression lastCompare = ApiHelper.StringCompatibleExpression(comparer, xkey, rkey);
|
BinaryExpression lastCompare = ApiHelper.StringCompatibleExpression(comparer, xkey, rkey);
|
||||||
|
|
||||||
|
// Comparing a value with null always return false for nulls so we must add nulls to the results manually.
|
||||||
|
// Postgres sorts them after values so we will do the same
|
||||||
|
// We only add this condition if the collumn type is nullable
|
||||||
|
if (Nullable.GetUnderlyingType(property.PropertyType) != null)
|
||||||
|
{
|
||||||
|
BinaryExpression equalNull = Expression.Equal(xkey, Expression.Constant(null));
|
||||||
|
lastCompare = Expression.OrElse(lastCompare, equalNull);
|
||||||
|
}
|
||||||
|
|
||||||
compare = compare != null
|
compare = compare != null
|
||||||
? Expression.AndAlso(compare, lastCompare)
|
? Expression.AndAlso(compare, lastCompare)
|
||||||
: lastCompare;
|
: lastCompare;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user