mirror of
https://github.com/Kareadita/Kavita.git
synced 2026-05-21 07:06:33 -04:00
OPDS Performance Enhancements (#4332)
Co-authored-by: Amelia <77553571+Fesaa@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
using System.Linq;
|
||||
using API.Entities;
|
||||
using API.Services.Tasks.Scanner.Parser;
|
||||
|
||||
namespace API.Extensions.QueryExtensions;
|
||||
|
||||
public static class ChapterQueryExtensions
|
||||
{
|
||||
public static IOrderedQueryable<Chapter> ApplyDefaultChapterOrdering(this IQueryable<Chapter> query)
|
||||
{
|
||||
return query
|
||||
.OrderBy(c =>
|
||||
// Priority 1: Regular volumes (not loose leaf, not special)
|
||||
c.Volume.Number == Parser.LooseLeafVolumeNumber ||
|
||||
c.Volume.Number == Parser.SpecialVolumeNumber ? 1 : 0)
|
||||
.ThenBy(c =>
|
||||
// Priority 2: Loose leaf over specials
|
||||
c.Volume.Number == Parser.SpecialVolumeNumber ? 1 : 0)
|
||||
// Priority 3: Non-special chapters
|
||||
.ThenBy(c => c.IsSpecial ? 1 : 0)
|
||||
.ThenBy(c => c.Volume.Number)
|
||||
.ThenBy(c => c.SortOrder);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
using System.Linq;
|
||||
using AutoMapper;
|
||||
using AutoMapper.QueryableExtensions;
|
||||
|
||||
namespace API.Extensions.QueryExtensions;
|
||||
|
||||
public static class ProjectToExtensions
|
||||
{
|
||||
public static IQueryable<TDestination> ProjectToWithProgress<TSource, TDestination>(
|
||||
this IQueryable<TSource> queryable,
|
||||
IConfigurationProvider config,
|
||||
int userId)
|
||||
{
|
||||
return queryable.ProjectTo<TDestination>(config, new { userId });
|
||||
}
|
||||
|
||||
// Convenience overload taking IMapper directly
|
||||
public static IQueryable<TDestination> ProjectToWithProgress<TSource, TDestination>(
|
||||
this IQueryable<TSource> queryable,
|
||||
IMapper mapper,
|
||||
int userId)
|
||||
{
|
||||
return queryable.ProjectTo<TDestination>(mapper.ConfigurationProvider, new { userId });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user