Build ErsatzTV Image / CI image pin matches docker/ci (pull_request) Successful in 5s
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 9s
Build ErsatzTV Image / decisions.md append-only (pull_request) Successful in 7s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 7m10s
Build ErsatzTV Image / Functional E2E (curl contracts) (pull_request) Successful in 5m12s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 14m53s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 12m39s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 14m31s
The all-items endpoint fired ten index searches with limit:0 (every hit), so a broad authenticated query materialized the whole index into one response. Add optional pageNum/pageSize (clamped 1..1000; pageNum 0..2_000_000 so skip can't overflow int) and an additive per-kind Totals on the response; the SPA add-all flow now pages to completeness instead of a single unbounded fetch. - SearchController.SearchAllItems: clamp params (Logs §1 precedent), map Totals - QuerySearchIndexAllItemsHandler: skip=pageNum*pageSize, limit=pageSize, read SearchResult.TotalCount per kind - SearchResultAllItemsResponseModel: additive Totals (frozen-v1-safe) - web/src/api/search.ts: getSearchAllItems paging params + getAllSearchItemIds (pages until each kind hits its total; empty-page safety break) - tests: controller clamp/thread/totals, handler skip/limit/totals, SPA paging - docs: decisions.md 2026-07-18 (#293), api-conventions.md §5; regenerated OpenAPI Design: issue option (a) full pagination, operator-confirmed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
78 lines
3.1 KiB
C#
78 lines
3.1 KiB
C#
using ErsatzTV.Core.Interfaces.Search;
|
|
using ErsatzTV.Core.Search;
|
|
using ErsatzTV.Infrastructure.Search;
|
|
|
|
namespace ErsatzTV.Application.Search;
|
|
|
|
public class QuerySearchIndexAllItemsHandler(ISearchIndex searchIndex)
|
|
: IRequestHandler<QuerySearchIndexAllItems, SearchResultAllItemsViewModel>
|
|
{
|
|
public async Task<SearchResultAllItemsViewModel> Handle(
|
|
QuerySearchIndexAllItems request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
int skip = request.PageNum * request.PageSize;
|
|
int limit = request.PageSize;
|
|
|
|
(List<int> Ids, int Total) movies =
|
|
await GetIds(LuceneSearchIndex.MovieType, request.Query, skip, limit, cancellationToken);
|
|
(List<int> Ids, int Total) shows =
|
|
await GetIds(LuceneSearchIndex.ShowType, request.Query, skip, limit, cancellationToken);
|
|
(List<int> Ids, int Total) seasons =
|
|
await GetIds(LuceneSearchIndex.SeasonType, request.Query, skip, limit, cancellationToken);
|
|
(List<int> Ids, int Total) episodes =
|
|
await GetIds(LuceneSearchIndex.EpisodeType, request.Query, skip, limit, cancellationToken);
|
|
(List<int> Ids, int Total) artists =
|
|
await GetIds(LuceneSearchIndex.ArtistType, request.Query, skip, limit, cancellationToken);
|
|
(List<int> Ids, int Total) musicVideos =
|
|
await GetIds(LuceneSearchIndex.MusicVideoType, request.Query, skip, limit, cancellationToken);
|
|
(List<int> Ids, int Total) otherVideos =
|
|
await GetIds(LuceneSearchIndex.OtherVideoType, request.Query, skip, limit, cancellationToken);
|
|
(List<int> Ids, int Total) songs =
|
|
await GetIds(LuceneSearchIndex.SongType, request.Query, skip, limit, cancellationToken);
|
|
(List<int> Ids, int Total) images =
|
|
await GetIds(LuceneSearchIndex.ImageType, request.Query, skip, limit, cancellationToken);
|
|
(List<int> Ids, int Total) remoteStreams =
|
|
await GetIds(LuceneSearchIndex.RemoteStreamType, request.Query, skip, limit, cancellationToken);
|
|
|
|
return new SearchResultAllItemsViewModel(
|
|
movies.Ids,
|
|
shows.Ids,
|
|
seasons.Ids,
|
|
episodes.Ids,
|
|
artists.Ids,
|
|
musicVideos.Ids,
|
|
otherVideos.Ids,
|
|
songs.Ids,
|
|
images.Ids,
|
|
remoteStreams.Ids,
|
|
new SearchResultAllItemsTotals(
|
|
movies.Total,
|
|
shows.Total,
|
|
seasons.Total,
|
|
episodes.Total,
|
|
artists.Total,
|
|
musicVideos.Total,
|
|
otherVideos.Total,
|
|
songs.Total,
|
|
images.Total,
|
|
remoteStreams.Total));
|
|
}
|
|
|
|
private async Task<(List<int> Ids, int Total)> GetIds(
|
|
string type,
|
|
string query,
|
|
int skip,
|
|
int limit,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
SearchResult result = await searchIndex.Search(
|
|
$"type:{type} AND ({query})",
|
|
string.Empty,
|
|
skip,
|
|
limit,
|
|
cancellationToken);
|
|
return (result.Items.Map(i => i.Id).ToList(), result.TotalCount);
|
|
}
|
|
}
|