Background Prefetching for Kavita+ (#2707)
This commit is contained in:
parent
f616b99585
commit
5dc5029a75
35 changed files with 3300 additions and 100 deletions
|
|
@ -143,6 +143,12 @@ public sealed class DataContext : IdentityDbContext<AppUser, AppRole, int,
|
|||
builder.Entity<AppUserSideNavStream>()
|
||||
.HasIndex(e => e.Visible)
|
||||
.IsUnique(false);
|
||||
|
||||
builder.Entity<ExternalSeriesMetadata>()
|
||||
.HasOne(em => em.Series)
|
||||
.WithOne(s => s.ExternalSeriesMetadata)
|
||||
.HasForeignKey<ExternalSeriesMetadata>(em => em.SeriesId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
}
|
||||
|
||||
#nullable enable
|
||||
|
|
|
|||
2871
API/Data/Migrations/20240209224347_DBTweaks.Designer.cs
generated
Normal file
2871
API/Data/Migrations/20240209224347_DBTweaks.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load diff
29
API/Data/Migrations/20240209224347_DBTweaks.cs
Normal file
29
API/Data/Migrations/20240209224347_DBTweaks.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace API.Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class DBTweaks : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ExternalRecommendation_Series_SeriesId",
|
||||
table: "ExternalRecommendation");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ExternalRecommendation_Series_SeriesId",
|
||||
table: "ExternalRecommendation",
|
||||
column: "SeriesId",
|
||||
principalTable: "Series",
|
||||
principalColumn: "Id");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2398,15 +2398,6 @@ namespace API.Data.Migrations
|
|||
b.Navigation("Chapter");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.Metadata.ExternalRecommendation", b =>
|
||||
{
|
||||
b.HasOne("API.Entities.Series", "Series")
|
||||
.WithMany()
|
||||
.HasForeignKey("SeriesId");
|
||||
|
||||
b.Navigation("Series");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("API.Entities.Metadata.ExternalSeriesMetadata", b =>
|
||||
{
|
||||
b.HasOne("API.Entities.Series", "Series")
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ using Microsoft.AspNetCore.Identity;
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Data.Repositories;
|
||||
#nullable enable
|
||||
|
||||
public interface IExternalSeriesMetadataRepository
|
||||
{
|
||||
|
|
@ -28,6 +29,7 @@ public interface IExternalSeriesMetadataRepository
|
|||
void Remove(IEnumerable<ExternalReview>? reviews);
|
||||
void Remove(IEnumerable<ExternalRating>? ratings);
|
||||
void Remove(IEnumerable<ExternalRecommendation>? recommendations);
|
||||
void Remove(ExternalSeriesMetadata metadata);
|
||||
Task<ExternalSeriesMetadata?> GetExternalSeriesMetadata(int seriesId);
|
||||
Task<bool> ExternalSeriesMetadataNeedsRefresh(int seriesId);
|
||||
Task<SeriesDetailPlusDto> GetSeriesDetailPlusDto(int seriesId);
|
||||
|
|
@ -70,18 +72,24 @@ public class ExternalSeriesMetadataRepository : IExternalSeriesMetadataRepositor
|
|||
_context.ExternalReview.RemoveRange(reviews);
|
||||
}
|
||||
|
||||
public void Remove(IEnumerable<ExternalRating> ratings)
|
||||
public void Remove(IEnumerable<ExternalRating>? ratings)
|
||||
{
|
||||
if (ratings == null) return;
|
||||
_context.ExternalRating.RemoveRange(ratings);
|
||||
}
|
||||
|
||||
public void Remove(IEnumerable<ExternalRecommendation> recommendations)
|
||||
public void Remove(IEnumerable<ExternalRecommendation>? recommendations)
|
||||
{
|
||||
if (recommendations == null) return;
|
||||
_context.ExternalRecommendation.RemoveRange(recommendations);
|
||||
}
|
||||
|
||||
public void Remove(ExternalSeriesMetadata? metadata)
|
||||
{
|
||||
if (metadata == null) return;
|
||||
_context.ExternalSeriesMetadata.Remove(metadata);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the ExternalSeriesMetadata entity for the given Series including all linked tables
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ public interface ILibraryRepository
|
|||
Task<IList<Library>> GetAllWithCoversInDifferentEncoding(EncodeFormat encodeFormat);
|
||||
Task<bool> GetAllowsScrobblingBySeriesId(int seriesId);
|
||||
|
||||
Task<IDictionary<int, LibraryType>> GetLibraryTypesBySeriesIdsAsync(IList<int> seriesIds);
|
||||
}
|
||||
|
||||
public class LibraryRepository : ILibraryRepository
|
||||
|
|
@ -352,4 +353,16 @@ public class LibraryRepository : ILibraryRepository
|
|||
.Select(s => s.Library.AllowScrobbling)
|
||||
.SingleOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<IDictionary<int, LibraryType>> GetLibraryTypesBySeriesIdsAsync(IList<int> seriesIds)
|
||||
{
|
||||
return await _context.Series
|
||||
.Where(series => seriesIds.Contains(series.Id))
|
||||
.Select(series => new
|
||||
{
|
||||
series.Id,
|
||||
series.Library.Type
|
||||
})
|
||||
.ToDictionaryAsync(entity => entity.Id, entity => entity.Type);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ public enum SeriesIncludes
|
|||
ExternalReviews = 64,
|
||||
ExternalRatings = 128,
|
||||
ExternalRecommendations = 256,
|
||||
ExternalMetadata = 512
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -551,7 +552,7 @@ public class SeriesRepository : ISeriesRepository
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns Volumes, Metadata, and Collection Tags
|
||||
/// Returns Full Series including all external links
|
||||
/// </summary>
|
||||
/// <param name="seriesIds"></param>
|
||||
/// <returns></returns>
|
||||
|
|
@ -559,9 +560,20 @@ public class SeriesRepository : ISeriesRepository
|
|||
{
|
||||
return await _context.Series
|
||||
.Include(s => s.Volumes)
|
||||
.Include(s => s.Relations)
|
||||
.Include(s => s.Metadata)
|
||||
.ThenInclude(m => m.CollectionTags)
|
||||
.Include(s => s.Relations)
|
||||
|
||||
|
||||
.Include(s => s.ExternalSeriesMetadata)
|
||||
|
||||
.Include(s => s.ExternalSeriesMetadata)
|
||||
.ThenInclude(e => e.ExternalRatings)
|
||||
.Include(s => s.ExternalSeriesMetadata)
|
||||
.ThenInclude(e => e.ExternalReviews)
|
||||
.Include(s => s.ExternalSeriesMetadata)
|
||||
.ThenInclude(e => e.ExternalRecommendations)
|
||||
|
||||
.Where(s => seriesIds.Contains(s.Id))
|
||||
.AsSplitQuery()
|
||||
.ToListAsync();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue