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.
124 lines
9.0 KiB
C#
124 lines
9.0 KiB
C#
#region ========================================================================= USING =====================================================================================
|
|
using Lumina.Domain.Common.Primitives;
|
|
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
|
|
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
|
|
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
#endregion
|
|
|
|
namespace Lumina.Application.Common.DataAccess.Repositories.Books;
|
|
|
|
/// <summary>
|
|
/// Interface for the repository for books.
|
|
/// </summary>
|
|
public interface IBookRepository : IRepository<BookEntity>,
|
|
IInsertRepositoryAction<BookEntity>,
|
|
IUpdateRepositoryAction<BookEntity>,
|
|
IGetByIdRepositoryAction<BookEntity, Guid>,
|
|
IGetAllRepositoryAction<BookEntity>,
|
|
IGetPaginatedRepositoryAction<BookEntity>
|
|
{
|
|
/// <summary>
|
|
/// Gets all the books of the media library identified by <paramref name="libraryId"/>.
|
|
/// </summary>
|
|
/// <param name="libraryId">The Id of the media library whose books are retrieved.</param>
|
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
|
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of <see cref="BookEntity"/>, or an error.</returns>
|
|
Task<Result<IEnumerable<BookEntity>>> GetByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken);
|
|
|
|
/// <summary>
|
|
/// Gets the book of the media library identified by <paramref name="libraryId"/> that is stored at the provided <paramref name="path"/>.
|
|
/// </summary>
|
|
/// <param name="libraryId">The Id of the media library whose book is retrieved.</param>
|
|
/// <param name="path">The file system path of the book to be retrieved.</param>
|
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
|
/// <returns>An <see cref="Result{TValue}"/> containing either the <see cref="BookEntity"/> stored at the provided path, or an error.</returns>
|
|
Task<Result<BookEntity?>> GetByPathAsync(Guid libraryId, string path, CancellationToken cancellationToken);
|
|
|
|
/// <summary>
|
|
/// Gets a page of the books of the media library identified by <paramref name="libraryId"/> whose metadata has not been enriched yet,
|
|
/// ordered by path, using keyset pagination.
|
|
/// </summary>
|
|
/// <param name="libraryId">The Id of the media library whose books are retrieved.</param>
|
|
/// <param name="lastPath">The path of the last retrieved book, used for keyset pagination. Pass <see langword="null"/> to get the first page.</param>
|
|
/// <param name="pageSize">The maximum number of books to retrieve.</param>
|
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
|
/// <returns>An <see cref="Result{TValue}"/> containing either a page of books needing their metadata enriched, or an error.</returns>
|
|
Task<Result<IReadOnlyList<BookEntity>>> GetBooksNeedingMetadataAsync(Guid libraryId, string? lastPath, int pageSize, CancellationToken cancellationToken);
|
|
|
|
/// <summary>
|
|
/// Gets the number of books of the media library identified by <paramref name="libraryId"/> whose metadata has not been enriched yet.
|
|
/// </summary>
|
|
/// <param name="libraryId">The Id of the media library whose books are counted.</param>
|
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
|
/// <returns>An <see cref="Result{TValue}"/> containing either the number of books needing their metadata enriched, or an error.</returns>
|
|
Task<Result<int>> GetBooksNeedingMetadataCountAsync(Guid libraryId, CancellationToken cancellationToken);
|
|
|
|
/// <summary>
|
|
/// Gets a page of the books of the media library identified by <paramref name="libraryId"/> that need their artwork resolved,
|
|
/// meaning they lack at least one required piece of artwork with an enriched status, ordered by path, using keyset pagination.
|
|
/// </summary>
|
|
/// <param name="libraryId">The Id of the media library whose books are retrieved.</param>
|
|
/// <param name="lastPath">The path of the last retrieved book, used for keyset pagination. Pass <see langword="null"/> to get the first page.</param>
|
|
/// <param name="pageSize">The maximum number of books to retrieve.</param>
|
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
|
/// <returns>An <see cref="Result{TValue}"/> containing either a page of books needing their artwork resolved, or an error.</returns>
|
|
Task<Result<IReadOnlyList<BookEntity>>> GetBooksNeedingArtworkAsync(Guid libraryId, string? lastPath, int pageSize, CancellationToken cancellationToken);
|
|
|
|
/// <summary>
|
|
/// Gets the number of books of the media library identified by <paramref name="libraryId"/> that need their artwork resolved.
|
|
/// </summary>
|
|
/// <param name="libraryId">The Id of the media library whose books are counted.</param>
|
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
|
/// <returns>An <see cref="Result{TValue}"/> containing either the number of books needing their artwork resolved, or an error.</returns>
|
|
Task<Result<int>> GetBooksNeedingArtworkCountAsync(Guid libraryId, CancellationToken cancellationToken);
|
|
|
|
/// <summary>
|
|
/// Resets the enrichment state of the books stored at the provided <paramref name="paths"/> in the media library identified by
|
|
/// <paramref name="libraryId"/>, so that they are re-enriched, because their content changed since the last scan.
|
|
/// </summary>
|
|
/// <param name="libraryId">The Id of the media library whose books are reset.</param>
|
|
/// <param name="paths">The file system paths of the books whose enrichment state is reset.</param>
|
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
|
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
|
Task<Result<Updated>> ResetEnrichmentStateForPathsAsync(Guid libraryId, IReadOnlyCollection<string> paths, CancellationToken cancellationToken);
|
|
|
|
/// <summary>
|
|
/// Resets the metadata enrichment status of all the books of the media library identified by <paramref name="libraryId"/>,
|
|
/// so that they are re-enriched, because the metadata provider configuration of the library changed.
|
|
/// </summary>
|
|
/// <param name="libraryId">The Id of the media library whose books are reset.</param>
|
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
|
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
|
Task<Result<Updated>> ResetMetadataStatusForLibraryAsync(Guid libraryId, CancellationToken cancellationToken);
|
|
|
|
/// <summary>
|
|
/// Resets the artwork status of all the artwork of the books of the media library identified by <paramref name="libraryId"/>,
|
|
/// so that they are re-resolved, because the artwork provider configuration of the library changed.
|
|
/// </summary>
|
|
/// <param name="libraryId">The Id of the media library whose artwork is reset.</param>
|
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
|
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
|
Task<Result<Updated>> ResetArtworkStatusForLibraryAsync(Guid libraryId, CancellationToken cancellationToken);
|
|
|
|
/// <summary>
|
|
/// Gets the display names of the author of the books identified by the provided <paramref name="bookIds"/>,
|
|
/// keyed by the Id of the book, or <see langword="null"/> when a book has no author.
|
|
/// </summary>
|
|
/// <param name="bookIds">The unique identifiers of the books whose authors are retrieved.</param>
|
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
|
/// <returns>An <see cref="Result{TValue}"/> containing either the display names of the authors of the books, keyed by book Id, or an error.</returns>
|
|
Task<Result<IReadOnlyDictionary<Guid, string?>>> GetAuthorsDisplayNamesByBookIdsAsync(IReadOnlyCollection<Guid> bookIds, CancellationToken cancellationToken);
|
|
|
|
/// <summary>
|
|
/// Deletes the book identified by <paramref name="bookId"/>.
|
|
/// </summary>
|
|
/// <param name="bookId">The Id of the book to delete.</param>
|
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
|
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
|
Task<Result<Deleted>> DeleteAsync(Guid bookId, CancellationToken cancellationToken);
|
|
}
|