mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Splits the single combined enrichment phase of the media library scan into independent, modular jobs, so that the metadata and the artwork of a book are enriched separately and only when their respective triggers fire. - Adds the MediaContributorRoleCategory enum (Other first, then Author, Translator, Illustrator, Publisher and Narrator) and makes the role category canonical, so that roles describing the same kind of contribution are never treated as distinct. - Realizes the media contributor bounded context: a MediaContributor is a person, unique by display name, without a role. The role moves to the per-work participation (BookContributors), so that a single contributor can play multiple roles. Contributors are created and linked by the metadata enrichment job, and exposed to subsequent jobs. - Makes the Book aggregate pure: the enrichment tracking state (metadata status, providers, timestamps and covers) no longer lives on the domain aggregate, but stays in the Books table, managed directly by the jobs. - Models artwork generically as a BookArtwork child table (type, ordinal, content hash, status and provider), so that each piece of artwork is tracked independently and a change of one does not require the others to be re-fetched. - Splits the scan DAG into ResultsSave, ProviderConfigurationInvalidation, MetadataEnrichment and ArtworkEnrichment jobs. The invalidation job fingerprints the provider configuration of a library and resets the enrichment state of the affected channel when it changed. The artwork job resolves the missing artwork, hashing it to detect identical covers and skip re-copying. Content-changed books are reset by the results save job. - Deletes the book and its stored artwork when the file disappears from the library. - Adds the migration creating the new tables, backfilling the existing covers into the artwork table, and adding the configuration fingerprints. - Localizes the new scan job stages, and fixes the invalidation job wiping the library content locations by persisting the fingerprints through the change tracker instead of the repository update action.
116 lines
4.3 KiB
C#
116 lines
4.3 KiB
C#
#region ========================================================================= USING =====================================================================================
|
|
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
using System;
|
|
#endregion
|
|
|
|
namespace Lumina.DataAccess.Common.Configuration;
|
|
|
|
/// <summary>
|
|
/// Configures the entity mapping for the <see cref="LibraryEntity"/> entity.
|
|
/// </summary>
|
|
public class LibraryConfiguration : IEntityTypeConfiguration<LibraryEntity>
|
|
{
|
|
/// <summary>
|
|
/// Configures the <see cref="LibraryEntity"/> entity.
|
|
/// </summary>
|
|
/// <param name="builder">The builder to be used to configure the entity.</param>
|
|
public void Configure(EntityTypeBuilder<LibraryEntity> builder)
|
|
{
|
|
builder.ToTable("Libraries");
|
|
builder.HasKey(library => library.Id);
|
|
builder.Property(library => library.Id)
|
|
.ValueGeneratedNever() // because EF always tries to generate the value for the Id, and because we generate it as part of the aggregate root, we need to tell EF not to generate it
|
|
.HasColumnOrder(0);
|
|
|
|
builder.Property(library => library.Title)
|
|
.IsRequired()
|
|
.HasMaxLength(255)
|
|
.HasColumnOrder(1);
|
|
|
|
builder.Property(library => library.LibraryType)
|
|
.IsRequired()
|
|
.HasConversion<string>()
|
|
.HasColumnOrder(2);
|
|
|
|
builder.Property(library => library.CoverImage)
|
|
.HasMaxLength(255)
|
|
.HasDefaultValue(null)
|
|
.HasColumnOrder(3);
|
|
|
|
builder.Property(library => library.IsEnabled)
|
|
.HasDefaultValue(true)
|
|
.HasColumnOrder(4);
|
|
|
|
builder.Property(library => library.IsLocked)
|
|
.HasColumnOrder(5);
|
|
|
|
builder.Property(library => library.CanDownloadMetadataFromWeb)
|
|
.HasDefaultValue(true)
|
|
.HasColumnOrder(6);
|
|
|
|
builder.Property(library => library.ShouldSaveMetadataInMediaDirectories)
|
|
.HasColumnOrder(7);
|
|
|
|
builder.Property(library => library.ShouldSkipUnchangedDirectoriesDuringScan)
|
|
.HasColumnOrder(8);
|
|
|
|
builder.Property(library => library.MetadataProvidersConfigurationFingerprint)
|
|
.HasMaxLength(64)
|
|
.HasDefaultValue(null)
|
|
.HasColumnOrder(9);
|
|
|
|
builder.Property(library => library.ArtworkProvidersConfigurationFingerprint)
|
|
.HasMaxLength(64)
|
|
.HasDefaultValue(null)
|
|
.HasColumnOrder(10);
|
|
|
|
// one user with many libraries
|
|
builder.HasOne(library => library.User)
|
|
.WithMany(user => user.Libraries)
|
|
.HasForeignKey(library => library.UserId)
|
|
.IsRequired();
|
|
|
|
// one library with many scans
|
|
builder.HasMany(library => library.LibraryScans)
|
|
.WithOne(libraryScan => libraryScan.Library)
|
|
.HasForeignKey(libraryScan => libraryScan.LibraryId)
|
|
.OnDelete(DeleteBehavior.Cascade); // deleting a library deletes library scans
|
|
|
|
// using OwnsMany because paths are domain Value Objects, thus they have no independent identity, and their lifecycle is bound to the Library
|
|
builder.OwnsMany(library => library.ContentLocations, contentLocationBuilder =>
|
|
{
|
|
contentLocationBuilder.ToTable("LibraryContentLocations");
|
|
contentLocationBuilder.WithOwner()
|
|
.HasForeignKey("LibraryId");
|
|
|
|
contentLocationBuilder.Property<Guid>("Id")
|
|
.ValueGeneratedOnAdd();
|
|
contentLocationBuilder.HasKey("Id");
|
|
|
|
contentLocationBuilder.Property(location => location.Path)
|
|
.HasColumnName("Path")
|
|
.HasMaxLength(260)
|
|
.IsRequired();
|
|
});
|
|
|
|
// audit
|
|
builder.Property(library => library.CreatedOnUtc)
|
|
.IsRequired()
|
|
.HasColumnOrder(11);
|
|
|
|
builder.Property(library => library.CreatedBy)
|
|
.IsRequired()
|
|
.HasColumnOrder(12);
|
|
|
|
builder.Property(library => library.UpdatedOnUtc)
|
|
.HasDefaultValue(null)
|
|
.HasColumnOrder(13);
|
|
|
|
builder.Property(library => library.UpdatedBy)
|
|
.HasDefaultValue(null)
|
|
.HasColumnOrder(14);
|
|
}
|
|
}
|