Files
ersatztv/ErsatzTV.Application/Search/Queries/SearchSmartCollectionsHandler.cs
T
timothyandClaude Opus 4.8 3bca000e27
Build ErsatzTV Image / CI image pin matches docker/ci (pull_request) Successful in 6s
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 10s
Build ErsatzTV Image / decisions.md append-only (pull_request) Successful in 21s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 13m34s
Build ErsatzTV Image / Functional E2E (curl contracts) (pull_request) Successful in 15m21s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 16m19s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 19m36s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 19m37s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
fix(425): address adversarial review — hide owned artifacts from schedule picker
Independent review found a blocker + two mediums:
- BLOCKER: SearchSmartCollections/SearchMultiCollections (the scheduling
  collection picker) didn't filter OwnedByChannelId, so a user could select a
  system-owned auto-tune artifact into their own schedule item — a later channel
  delete would then cascade-delete that schedule item (ProgramScheduleItem->
  MultiCollection is OnDelete(Cascade)). Both handlers now exclude owned rows;
  regression test added (CollectionPickerHidesOwnedTests).
- MEDIUM: TryStampOwnership now runs on CancellationToken.None (post-commit
  convention #254) and stamps the MC + member SmartCollections in one
  transaction, so a late cancel or mid-way failure can't leave a permanent
  orphan / list leak.
- Documented the movie-remainder weight clamp bound (>1000 un-touched movies
  can't express the exact ratio — the 1..1000 weight-column bound from #70).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-18 03:52:06 +02:00

28 lines
1.2 KiB
C#

using ErsatzTV.Application.MediaCollections;
using ErsatzTV.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
using static ErsatzTV.Application.MediaCollections.Mapper;
namespace ErsatzTV.Application.Search;
public class SearchSmartCollectionsHandler(IDbContextFactory<TvContext> dbContextFactory)
: IRequestHandler<SearchSmartCollections, List<SmartCollectionViewModel>>
{
public async Task<List<SmartCollectionViewModel>> Handle(
SearchSmartCollections request,
CancellationToken cancellationToken)
{
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
return await dbContext.SmartCollections
.AsNoTracking()
// Hide system-owned auto-tune weighted artifacts (#425) from the scheduling picker: selecting one
// into a user schedule would let a later channel delete cascade away that schedule item.
.Where(sc => sc.OwnedByChannelId == null)
.Where(sc => EF.Functions.Like(sc.Name, $"%{request.Query}%"))
.OrderBy(sc => sc.Name)
.Take(10)
.ToListAsync(cancellationToken)
.Map(list => list.Map(ProjectToViewModel).ToList());
}
}