diff --git a/CHANGELOG.md b/CHANGELOG.md index cc24bdcea..cb1ac948e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Automatically remove already-played playout items from (continuous) scripted schedules - Extract embedded text subtitles (when enabled in settings) on channels that use custom stream selectors - Fix subtitle playback using Next streaming engine +- Fix bug where search results for deleted manual collections would continue to appear ### Changed - Upgrade Intel driver in docker containers to support latest Battlemage devices (e.g. B70) diff --git a/ErsatzTV.Application/MediaCollections/Commands/DeleteCollectionHandler.cs b/ErsatzTV.Application/MediaCollections/Commands/DeleteCollectionHandler.cs index c18a00c11..cab373d36 100644 --- a/ErsatzTV.Application/MediaCollections/Commands/DeleteCollectionHandler.cs +++ b/ErsatzTV.Application/MediaCollections/Commands/DeleteCollectionHandler.cs @@ -1,5 +1,7 @@ using ErsatzTV.Core; using ErsatzTV.Core.Domain; +using ErsatzTV.Core.Interfaces.Metadata; +using ErsatzTV.Core.Interfaces.Repositories; using ErsatzTV.Core.Interfaces.Search; using ErsatzTV.Infrastructure.Data; using ErsatzTV.Infrastructure.Extensions; @@ -7,31 +9,38 @@ using Microsoft.EntityFrameworkCore; namespace ErsatzTV.Application.MediaCollections; -public class DeleteCollectionHandler : IRequestHandler> +public class DeleteCollectionHandler( + IDbContextFactory dbContextFactory, + ISearchTargets searchTargets, + IMediaCollectionRepository mediaCollectionRepository, + ISearchRepository searchRepository, + IFallbackMetadataProvider fallbackMetadataProvider, + ILanguageCodeService languageCodeService, + ISearchIndex searchIndex) + : IRequestHandler> { - private readonly IDbContextFactory _dbContextFactory; - private readonly ISearchTargets _searchTargets; - - public DeleteCollectionHandler(IDbContextFactory dbContextFactory, ISearchTargets searchTargets) - { - _dbContextFactory = dbContextFactory; - _searchTargets = searchTargets; - } - public async Task> Handle( DeleteCollection request, CancellationToken cancellationToken) { - await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); + await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken); Validation validation = await CollectionMustExist(dbContext, request, cancellationToken); return await validation.Apply(c => DoDeletion(dbContext, c, cancellationToken)); } private async Task DoDeletion(TvContext dbContext, Collection collection, CancellationToken cancellationToken) { + var itemIds = (await mediaCollectionRepository.GetItems(collection.Id)).Map(i => i.Id).ToList(); dbContext.Collections.Remove(collection); await dbContext.SaveChangesAsync(cancellationToken); - _searchTargets.SearchTargetsChanged(); + await searchIndex.RebuildItems( + searchRepository, + fallbackMetadataProvider, + languageCodeService, + itemIds, + cancellationToken); + searchIndex.Commit(); + searchTargets.SearchTargetsChanged(); return Unit.Default; }