From 7869cd66618fc7c53984cbcff30c95083106536d Mon Sep 17 00:00:00 2001 From: Jos Vooges | STH Date: Thu, 10 Sep 2026 22:31:54 +0200 Subject: [PATCH] Speed up client home by loading shelves in parallel. Shelf item queries no longer run one-by-one; favorites load alongside them. Response shape and shelf order stay the same. Co-authored-by: Cursor --- apps/master-api/src/viewer/service.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/apps/master-api/src/viewer/service.ts b/apps/master-api/src/viewer/service.ts index e35b03d..6e39c59 100644 --- a/apps/master-api/src/viewer/service.ts +++ b/apps/master-api/src/viewer/service.ts @@ -692,8 +692,19 @@ export class ViewerService { }); } - for (const shelf of ordered) { - const items = await this.shelfItems(shelf.id, shelf.kind, 48, kidsMode); + // Plank-items parallel laden (volgorde van `ordered` blijft behouden via Promise.all-index). + // Favorites hangt niet van planken af → tegelijk ophalen i.p.v. erna. + const [shelfPayloads, favorites] = await Promise.all([ + Promise.all( + ordered.map(async (shelf) => { + const items = await this.shelfItems(shelf.id, shelf.kind, 48, kidsMode); + return { shelf, items }; + }) + ), + this.listFavorites(profileId, kidsMode), + ]); + + for (const { shelf, items } of shelfPayloads) { if (items.length) { const homepageLabel = shelf.homepageName?.trim(); rows.push({ @@ -711,7 +722,7 @@ export class ViewerService { continueWatching: continueItems, spotlight, shelves: rows, - favorites: await this.listFavorites(profileId, kidsMode), + favorites, }; }