perf: use dedicated /books/ongoing and /series/ongoing Stripstream endpoints
All checks were successful
Build, Push & Deploy / deploy (push) Successful in 4m52s

Replaces manual ongoing series derivation (fetching 200 series per library)
with the new API endpoints, reducing API calls and improving accuracy.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-15 16:25:49 +01:00
parent 1d03cfc177
commit 53af9db046

View File

@@ -18,6 +18,8 @@ import type {
StripstreamLibraryResponse, StripstreamLibraryResponse,
StripstreamBooksPage, StripstreamBooksPage,
StripstreamSeriesPage, StripstreamSeriesPage,
StripstreamBookItem,
StripstreamSeriesItem,
StripstreamBookDetails, StripstreamBookDetails,
StripstreamReadingProgressResponse, StripstreamReadingProgressResponse,
StripstreamSearchResponse, StripstreamSearchResponse,
@@ -196,59 +198,52 @@ export class StripstreamProvider implements IMediaProvider {
async getHomeData(): Promise<HomeData> { async getHomeData(): Promise<HomeData> {
const homeOpts = { revalidate: CACHE_TTL_MED, tags: [HOME_CACHE_TAG] }; const homeOpts = { revalidate: CACHE_TTL_MED, tags: [HOME_CACHE_TAG] };
const [ongoingBooksPage, booksPage, libraries] = await Promise.allSettled([ const [ongoingBooksResult, ongoingSeriesResult, booksPage, libraries] = await Promise.allSettled([
this.client.fetch<StripstreamBooksPage>("books", { limit: "10", reading_status: "reading" }, homeOpts), this.client.fetch<StripstreamBookItem[]>("books/ongoing", { limit: "10" }, homeOpts),
this.client.fetch<StripstreamSeriesItem[]>("series/ongoing", { limit: "10" }, homeOpts),
this.client.fetch<StripstreamBooksPage>("books", { limit: "10" }, homeOpts), this.client.fetch<StripstreamBooksPage>("books", { limit: "10" }, homeOpts),
this.client.fetch<StripstreamLibraryResponse[]>("libraries", undefined, { revalidate: CACHE_TTL_LONG, tags: [HOME_CACHE_TAG] }), this.client.fetch<StripstreamLibraryResponse[]>("libraries", undefined, { revalidate: CACHE_TTL_LONG, tags: [HOME_CACHE_TAG] }),
]); ]);
const ongoingBooks = ongoingBooksPage.status === "fulfilled" const onDeck = ongoingBooksResult.status === "fulfilled"
? ongoingBooksPage.value.items.map(StripstreamAdapter.toNormalizedBook) ? ongoingBooksResult.value.map(StripstreamAdapter.toNormalizedBook)
: []; : [];
const books = booksPage.status === "fulfilled" const ongoingSeries = ongoingSeriesResult.status === "fulfilled"
? ongoingSeriesResult.value.map(StripstreamAdapter.toNormalizedSeries)
: [];
const ongoingBooks = booksPage.status === "fulfilled"
? booksPage.value.items.filter((b) => b.reading_status === "reading").map(StripstreamAdapter.toNormalizedBook)
: [];
const recentlyRead = booksPage.status === "fulfilled"
? booksPage.value.items.map(StripstreamAdapter.toNormalizedBook) ? booksPage.value.items.map(StripstreamAdapter.toNormalizedBook)
: []; : [];
// Derive ongoing series from ongoing books (series with at least one book being read)
const ongoingSeriesNames = ongoingBooksPage.status === "fulfilled"
? Array.from(new Set(ongoingBooksPage.value.items.filter((b) => b.series).map((b) => b.series!)))
: [];
let ongoingSeries: NormalizedSeries[] = [];
let latestSeries: NormalizedSeries[] = []; let latestSeries: NormalizedSeries[] = [];
if (libraries.status === "fulfilled" && libraries.value.length > 0) { if (libraries.status === "fulfilled" && libraries.value.length > 0) {
const libs = libraries.value;
// Fetch all series from all libraries for ongoing matching and latest
const allSeriesResults = await Promise.allSettled( const allSeriesResults = await Promise.allSettled(
libs.map((lib) => libraries.value.map((lib) =>
this.client.fetch<StripstreamSeriesPage>( this.client.fetch<StripstreamSeriesPage>(
`libraries/${lib.id}/series`, `libraries/${lib.id}/series`,
{ limit: "200" }, { limit: "10" },
homeOpts homeOpts
) )
) )
); );
const allSeries = allSeriesResults latestSeries = allSeriesResults
.filter((r): r is PromiseFulfilledResult<StripstreamSeriesPage> => r.status === "fulfilled") .filter((r): r is PromiseFulfilledResult<StripstreamSeriesPage> => r.status === "fulfilled")
.flatMap((r) => r.value.items); .flatMap((r) => r.value.items)
ongoingSeries = allSeries
.filter((s) => ongoingSeriesNames.includes(s.name))
.map(StripstreamAdapter.toNormalizedSeries)
.slice(0, 10);
latestSeries = allSeries
.map(StripstreamAdapter.toNormalizedSeries) .map(StripstreamAdapter.toNormalizedSeries)
.slice(0, 10); .slice(0, 10);
} }
return { return {
ongoing: ongoingSeries, ongoing: ongoingSeries,
ongoingBooks: ongoingBooks, ongoingBooks,
recentlyRead: books, recentlyRead,
onDeck: [], onDeck,
latestSeries, latestSeries,
}; };
} }