mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -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),
|
||||
PreviousEpisode = ep.Show.IsMovie
|
||||
? 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
|
||||
? 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),
|
||||
IsMovie = ep.Show.IsMovie
|
||||
};
|
||||
|
@ -168,6 +168,14 @@ namespace Kyoo.Core.Controllers
|
||||
foreach ((string key, bool desc) in sorts)
|
||||
{
|
||||
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.
|
||||
foreach ((string pKey, bool pDesc) in previousSteps)
|
||||
@ -186,6 +194,16 @@ namespace Kyoo.Core.Controllers
|
||||
MemberExpression xkey = Expression.Property(x, key);
|
||||
MemberExpression rkey = Expression.Property(referenceC, key);
|
||||
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
|
||||
? Expression.AndAlso(compare, lastCompare)
|
||||
: lastCompare;
|
||||
|
Loading…
x
Reference in New Issue
Block a user