mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 21:11:10 +00:00
Merge branch 'feature/add-metadata-aggregation' into feature/add-artwork-provider-and-metadata-aggregation
This commit is contained in:
commit
b47588cf83
168 files changed
+3503
-1062
No files matched your search
@@ -46,7 +46,7 @@ public class LibraryConfiguration : IEntityTypeConfiguration<LibraryEntity>
|
||||
builder.Property(library => library.IsLocked)
|
||||
.HasColumnOrder(5);
|
||||
|
||||
builder.Property(library => library.DownloadMetadataFromWeb)
|
||||
builder.Property(library => library.CanDownloadMetadataFromWeb)
|
||||
.HasDefaultValue(true)
|
||||
.HasColumnOrder(6);
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.Common.Configuration;
|
||||
@@ -43,10 +42,14 @@ public class UserSettingsConfiguration : IEntityTypeConfiguration<UserSettingsEn
|
||||
.IsRequired()
|
||||
.HasColumnOrder(3);
|
||||
|
||||
builder.Property(settings => settings.IgnoreThePrefixForAlphaPicker)
|
||||
builder.Property(settings => settings.ShouldIgnoreThePrefixForAlphaPicker)
|
||||
.IsRequired()
|
||||
.HasColumnOrder(4);
|
||||
|
||||
builder.Property(settings => settings.ShouldAggregateMetadataWhenMissing)
|
||||
.IsRequired()
|
||||
.HasColumnOrder(10);
|
||||
|
||||
builder.Property(settings => settings.IsThemeCachingEnabled)
|
||||
.IsRequired()
|
||||
.HasColumnOrder(9);
|
||||
|
||||
@@ -132,7 +132,7 @@ internal sealed class BookRepository : IBookRepository
|
||||
booksQuery = booksQuery.Where(filterSpecification.ToExpression());
|
||||
|
||||
// apply sorting based on the specified sortBy and sortOrder parameters
|
||||
booksQuery = ApplySorting(booksQuery, sortBy, sortOrder ?? SortOrder.Ascending, libraryFilter.IgnoreThePrefixForAlphaPicker);
|
||||
booksQuery = ApplySorting(booksQuery, sortBy, sortOrder ?? SortOrder.Ascending, libraryFilter.ShouldIgnoreThePrefixForAlphaPicker);
|
||||
|
||||
// if no pagination was requested, return all the books of the library
|
||||
if (paginationData is null)
|
||||
@@ -261,8 +261,8 @@ internal sealed class BookRepository : IBookRepository
|
||||
/// <param name="booksQuery">The query to sort.</param>
|
||||
/// <param name="sortBy">The field to sort by (case-insensitive).</param>
|
||||
/// <param name="sortOrder">The direction of the sorting.</param>
|
||||
/// <param name="ignoreThePrefixForAlphaPicker">Whether a leading "the " prefix of a title is ignored when deriving the title sort key, or not.</param>
|
||||
private static IOrderedQueryable<BookEntity> ApplySorting(IQueryable<BookEntity> booksQuery, string? sortBy, SortOrder sortOrder, bool ignoreThePrefixForAlphaPicker)
|
||||
/// <param name="shouldIgnoreThePrefixForAlphaPicker">Whether a leading "the " prefix of a title is ignored when deriving the title sort key, or not.</param>
|
||||
private static IOrderedQueryable<BookEntity> ApplySorting(IQueryable<BookEntity> booksQuery, string? sortBy, SortOrder sortOrder, bool shouldIgnoreThePrefixForAlphaPicker)
|
||||
{
|
||||
return sortBy?.ToLower() switch
|
||||
{
|
||||
@@ -276,8 +276,8 @@ internal sealed class BookRepository : IBookRepository
|
||||
? booksQuery.OrderByDescending(book => book.MetadataProvider)
|
||||
: booksQuery.OrderBy(book => book.MetadataProvider),
|
||||
_ => sortOrder == SortOrder.Descending
|
||||
? booksQuery.OrderByDescending(BuildTitleSortKey(ignoreThePrefixForAlphaPicker))
|
||||
: booksQuery.OrderBy(BuildTitleSortKey(ignoreThePrefixForAlphaPicker)),
|
||||
? booksQuery.OrderByDescending(BuildTitleSortKey(shouldIgnoreThePrefixForAlphaPicker))
|
||||
: booksQuery.OrderBy(BuildTitleSortKey(shouldIgnoreThePrefixForAlphaPicker)),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -286,9 +286,9 @@ internal sealed class BookRepository : IBookRepository
|
||||
/// the title lowercased, falling back to the original title when the title is <see langword="null"/> or empty, and optionally
|
||||
/// stripped of a leading "the " prefix.
|
||||
/// </summary>
|
||||
/// <param name="ignoreThePrefixForAlphaPicker">Whether a leading "the " prefix of a title is ignored when deriving the title sort key, or not.</param>
|
||||
/// <param name="shouldIgnoreThePrefixForAlphaPicker">Whether a leading "the " prefix of a title is ignored when deriving the title sort key, or not.</param>
|
||||
/// <returns>An expression that evaluates to the title sort key of a book.</returns>
|
||||
private static Expression<Func<BookEntity, string>> BuildTitleSortKey(bool ignoreThePrefixForAlphaPicker)
|
||||
private static Expression<Func<BookEntity, string>> BuildTitleSortKey(bool shouldIgnoreThePrefixForAlphaPicker)
|
||||
{
|
||||
ParameterExpression book = Expression.Parameter(typeof(BookEntity), "book");
|
||||
|
||||
@@ -306,7 +306,7 @@ internal sealed class BookRepository : IBookRepository
|
||||
|
||||
// when ignoring the "The " prefix, strip a leading "the " from the lowercased title
|
||||
Expression effectiveTitle = lowerTitle;
|
||||
if (ignoreThePrefixForAlphaPicker)
|
||||
if (shouldIgnoreThePrefixForAlphaPicker)
|
||||
{
|
||||
MethodCallExpression startsWithThe = Expression.Call(lowerTitle, s_startsWithMethod, Expression.Constant("the "));
|
||||
MethodCallExpression strippedTitle = Expression.Call(lowerTitle, s_substringMethod, Expression.Constant(4));
|
||||
@@ -332,7 +332,7 @@ internal sealed class BookRepository : IBookRepository
|
||||
// include the alpha key filter, if provided
|
||||
if (libraryFilter.FilterAlphaKey is not null)
|
||||
{
|
||||
BookAlphaFilterSpecification alphaFilterSpecification = new(libraryFilter.FilterAlphaKey, libraryFilter.IgnoreThePrefixForAlphaPicker);
|
||||
BookAlphaFilterSpecification alphaFilterSpecification = new(libraryFilter.FilterAlphaKey, libraryFilter.ShouldIgnoreThePrefixForAlphaPicker);
|
||||
filterSpecification = filterSpecification is null
|
||||
? alphaFilterSpecification
|
||||
: filterSpecification.And(alphaFilterSpecification);
|
||||
|
||||
+5
-5
@@ -23,17 +23,17 @@ internal sealed class BookAlphaFilterSpecification : FilterSpecification<BookEnt
|
||||
.GetMethod(nameof(SqliteDbFunctionsExtensions.Glob), [typeof(DbFunctions), typeof(string), typeof(string)])!;
|
||||
|
||||
private readonly string? _filterAlphaKey;
|
||||
private readonly bool _ignoreThePrefixForAlphaPicker;
|
||||
private readonly bool _shouldIgnoreThePrefixForAlphaPicker;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BookAlphaFilterSpecification"/> class.
|
||||
/// </summary>
|
||||
/// <param name="filterAlphaKey">The alpha key to filter by. A single ASCII letter, <see cref="LibraryItemAlphaKeys.NUMBER"/>, or <see cref="LibraryItemAlphaKeys.SYMBOL"/>.</param>
|
||||
/// <param name="ignoreThePrefixForAlphaPicker">Whether the leading "The " prefix of a title should be ignored when computing the alpha key, or not.</param>
|
||||
public BookAlphaFilterSpecification(string? filterAlphaKey, bool ignoreThePrefixForAlphaPicker)
|
||||
/// <param name="shouldIgnoreThePrefixForAlphaPicker">Whether the leading "The " prefix of a title should be ignored when computing the alpha key, or not.</param>
|
||||
public BookAlphaFilterSpecification(string? filterAlphaKey, bool shouldIgnoreThePrefixForAlphaPicker)
|
||||
{
|
||||
_filterAlphaKey = filterAlphaKey;
|
||||
_ignoreThePrefixForAlphaPicker = ignoreThePrefixForAlphaPicker;
|
||||
_shouldIgnoreThePrefixForAlphaPicker = shouldIgnoreThePrefixForAlphaPicker;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -82,7 +82,7 @@ internal sealed class BookAlphaFilterSpecification : FilterSpecification<BookEnt
|
||||
|
||||
// when ignoring the "The " prefix, strip a leading "the " from the lowercased title
|
||||
Expression effectiveTitle = lowerTitle;
|
||||
if (_ignoreThePrefixForAlphaPicker)
|
||||
if (_shouldIgnoreThePrefixForAlphaPicker)
|
||||
{
|
||||
MethodCallExpression startsWithThe = Expression.Call(lowerTitle, s_startsWithMethod, Expression.Constant("the "));
|
||||
MethodCallExpression strippedTitle = Expression.Call(lowerTitle, s_substringMethod, Expression.Constant(4));
|
||||
|
||||
@@ -33,6 +33,7 @@ public class LuminaDbContext : DbContext
|
||||
public virtual DbSet<RolePermissionEntity> RolePermissions { get; set; } = null!;
|
||||
public virtual DbSet<PluginEntity> Plugins { get; set; } = null!;
|
||||
public virtual DbSet<LibraryMetadataProviderConfigurationEntity> LibraryMetadataProviderConfigurations { get; set; } = null!;
|
||||
public virtual DbSet<LibraryArtworkProviderConfigurationEntity> LibraryArtworkProviderConfigurations { get; set; } = null!;
|
||||
public virtual DbSet<ThemeEntity> Themes { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -39,6 +39,7 @@ public class UnitOfWork : IUnitOfWork, IDisposable
|
||||
private ILibraryScanSnapshotRepository? _libraryScanSnapshotRepository;
|
||||
private ILibraryScanStagingResultsRepository? _libraryScanStagingResultsRepository;
|
||||
private ILibraryMetadataProviderConfigurationRepository? _libraryMetadataProviderConfigurationRepository;
|
||||
private IArtworkProviderConfigurationRepository? _artworkProviderConfigurationRepository;
|
||||
private IPluginRepository? _pluginRepository;
|
||||
private IThemeRepository? _themeRepository;
|
||||
private IUserRepository? _userRepository;
|
||||
@@ -176,6 +177,18 @@ public class UnitOfWork : IUnitOfWork, IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the library artwork provider configuration repository.
|
||||
/// </summary>
|
||||
public IArtworkProviderConfigurationRepository ArtworkProviderConfigurationRepository
|
||||
{
|
||||
get
|
||||
{
|
||||
_artworkProviderConfigurationRepository ??= new ArtworkProviderConfigurationRepository(_luminaDbContext);
|
||||
return _artworkProviderConfigurationRepository;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the plugin repository.
|
||||
/// </summary>
|
||||
@@ -242,6 +255,14 @@ public class UnitOfWork : IUnitOfWork, IDisposable
|
||||
await _luminaDbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detaches all the entities tracked by the unit of work, freeing the memory they occupy.
|
||||
/// </summary>
|
||||
public void ClearTrackedEntities()
|
||||
{
|
||||
_luminaDbContext.ChangeTracker.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Begins a new database transaction.
|
||||
/// </summary>
|
||||
|
||||
Reference in new issue
Block a user