Adds independent metadata and artwork enrichment

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.
This commit is contained in:
BinaryAlley committed 2026-08-27 14:41:49 +03:00
1 parent 4ee2976806
commit 565fe68239
98 files changed
+5845 -630

No files matched your search

@@ -0,0 +1,60 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.MediaContributors;
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaContributors;
/// <summary>
/// Fixture class for the <see cref="BookContributorEntity"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookContributorEntityFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="BookContributorEntity"/>.
/// </summary>
/// <param name="id">Optional. The Id of the participation.</param>
/// <param name="bookId">Optional. The Id of the book the contributor participated in.</param>
/// <param name="mediaContributorId">Optional. The Id of the media contributor.</param>
/// <param name="roleName">Optional. The display name of the role the contributor played in the book.</param>
/// <param name="roleCategory">Optional. The canonical category of the role the contributor played in the book.</param>
/// <returns>The created <see cref="BookContributorEntity"/>.</returns>
public BookContributorEntity Create(
Guid? id = null,
Guid? bookId = null,
Guid? mediaContributorId = null,
string? roleName = null,
MediaContributorRoleCategory? roleCategory = null)
{
return new BookContributorEntity
{
Id = id ?? Guid.NewGuid(),
BookId = bookId ?? Guid.NewGuid(),
MediaContributorId = mediaContributorId ?? Guid.NewGuid(),
RoleName = roleName ?? _faker.Lorem.Word(),
RoleCategory = roleCategory ?? _faker.PickRandom<MediaContributorRoleCategory>(),
CreatedOnUtc = _faker.Date.Past(),
CreatedBy = Guid.NewGuid(),
UpdatedOnUtc = null,
UpdatedBy = null
};
}
/// <summary>
/// Creates a list of <see cref="BookContributorEntity"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="BookContributorEntity"/> instances.</returns>
public List<BookContributorEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,63 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.MediaContributors;
using Lumina.Application.Fixtures.Common.Setup;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaContributors;
/// <summary>
/// Fixture class for the <see cref="MediaContributorEntity"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class MediaContributorEntityFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="MediaContributorEntity"/>.
/// </summary>
/// <param name="id">Optional. The Id of the media contributor.</param>
/// <param name="displayName">Optional. The name by which the contributor is popularly known.</param>
/// <param name="legalName">Optional. The legal name of the contributor.</param>
/// <param name="biography">Optional. The biography of the contributor.</param>
/// <param name="dateOfBirth">Optional. The date of birth of the contributor.</param>
/// <param name="dateOfDeath">Optional. The date of death of the contributor.</param>
/// <returns>The created <see cref="MediaContributorEntity"/>.</returns>
public MediaContributorEntity Create(
Guid? id = null,
string? displayName = null,
string? legalName = null,
string? biography = null,
DateOnly? dateOfBirth = null,
DateOnly? dateOfDeath = null)
{
return new MediaContributorEntity
{
Id = id ?? Guid.NewGuid(),
DisplayName = displayName ?? _faker.Person.FullName,
LegalName = legalName ?? _faker.Person.FullName,
Biography = biography ?? _faker.Lorem.Sentence(),
DateOfBirth = dateOfBirth ?? _faker.DateOnlyBetween(new DateOnly(1900, 1, 1), new DateOnly(2000, 12, 31)),
DateOfDeath = dateOfDeath,
CreatedOnUtc = _faker.Date.Past(),
CreatedBy = Guid.NewGuid(),
UpdatedOnUtc = null,
UpdatedBy = null
};
}
/// <summary>
/// Creates a list of <see cref="MediaContributorEntity"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="MediaContributorEntity"/> instances.</returns>
public List<MediaContributorEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -30,6 +30,8 @@ public class LibraryEntityFixture
/// <param name="canDownloadMetadataFromWeb">Whether the media library should download metadata from the web or not.</param>
/// <param name="shouldSaveMetadataInMediaDirectories">Whether the metadata should be saved in the media directories or not.</param>
/// <param name="shouldSkipUnchangedDirectoriesDuringScan">Whether unchanged directories should be skipped during a scan or not.</param>
/// <param name="metadataProvidersConfigurationFingerprint">Optional. The fingerprint of the metadata provider configuration of the media library.</param>
/// <param name="artworkProvidersConfigurationFingerprint">Optional. The fingerprint of the artwork provider configuration of the media library.</param>
/// <returns>The created media library entity.</returns>
public LibraryEntity Create(
Guid? id = null,
@@ -42,7 +44,9 @@ public class LibraryEntityFixture
bool isLocked = false,
bool canDownloadMetadataFromWeb = true,
bool shouldSaveMetadataInMediaDirectories = true,
bool shouldSkipUnchangedDirectoriesDuringScan = false)
bool shouldSkipUnchangedDirectoriesDuringScan = false,
string? metadataProvidersConfigurationFingerprint = null,
string? artworkProvidersConfigurationFingerprint = null)
{
return new Faker<LibraryEntity>()
.CustomInstantiator(f => new LibraryEntity
@@ -59,6 +63,8 @@ public class LibraryEntityFixture
CanDownloadMetadataFromWeb = canDownloadMetadataFromWeb,
ShouldSaveMetadataInMediaDirectories = shouldSaveMetadataInMediaDirectories,
ShouldSkipUnchangedDirectoriesDuringScan = shouldSkipUnchangedDirectoriesDuringScan,
MetadataProvidersConfigurationFingerprint = metadataProvidersConfigurationFingerprint,
ArtworkProvidersConfigurationFingerprint = artworkProvidersConfigurationFingerprint,
CreatedOnUtc = default,
CreatedBy = default,
UpdatedOnUtc = null,
@@ -0,0 +1,73 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
/// <summary>
/// Fixture class for the <see cref="BookArtworkEntity"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookArtworkEntityFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="BookArtworkEntity"/>.
/// </summary>
/// <param name="id">Optional. The Id of the artwork.</param>
/// <param name="bookId">Optional. The Id of the book the artwork belongs to.</param>
/// <param name="artworkType">Optional. The type of the artwork.</param>
/// <param name="ordinal">Optional. The ordinal of the artwork within its type.</param>
/// <param name="fileName">Optional. The relative file name of the stored artwork.</param>
/// <param name="contentHash">Optional. The content hash of the stored artwork.</param>
/// <param name="status">Optional. The status of the artwork enrichment.</param>
/// <param name="provider">Optional. The name of the plugin that resolved the artwork.</param>
/// <param name="lastUpdateUtc">Optional. The date and time when the artwork was last resolved.</param>
/// <returns>The created <see cref="BookArtworkEntity"/>.</returns>
public BookArtworkEntity Create(
Guid? id = null,
Guid? bookId = null,
ArtworkType? artworkType = null,
int? ordinal = null,
string? fileName = null,
ulong? contentHash = null,
ArtworkStatus? status = null,
string? provider = null,
DateTime? lastUpdateUtc = null)
{
return new BookArtworkEntity
{
Id = id ?? Guid.NewGuid(),
BookId = bookId ?? Guid.NewGuid(),
ArtworkType = artworkType ?? ArtworkType.Cover,
Ordinal = ordinal ?? 0,
FileName = fileName ?? _faker.System.FilePath(),
ContentHash = contentHash ?? (ulong)_faker.Random.ULong(),
Status = status ?? _faker.PickRandom<ArtworkStatus>(),
Provider = provider ?? _faker.Company.CompanyName(),
LastUpdateUtc = lastUpdateUtc ?? _faker.Date.Recent(),
CreatedOnUtc = _faker.Date.Past(),
CreatedBy = Guid.NewGuid(),
UpdatedOnUtc = null,
UpdatedBy = null
};
}
/// <summary>
/// Creates a list of <see cref="BookArtworkEntity"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="BookArtworkEntity"/> instances.</returns>
public List<BookArtworkEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -8,6 +8,7 @@ using Lumina.Contracts.DTO.MediaContributors;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -78,7 +79,7 @@ public class AddBookCommandFixture
default!
))
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(e => e.Category, f => f.Random.String2(f.Random.Number(1, 50)));
.RuleFor(e => e.Category, f => f.PickRandom<MediaContributorRoleCategory>());
Faker<MediaContributorNameDto> mediaContributorName = new Faker<MediaContributorNameDto>()
.CustomInstantiator(f => new MediaContributorNameDto(