pstream is dead; long live pstream taciturnaxolotl.github.io/pstream-ng/
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Concurrent Season Fetching for TV Shows

Pas c19fe775 41bd5cc4

+31 -15
+31 -15
src/backend/metadata/tmdb.ts
··· 361 361 362 362 // Fetch episodes for each season 363 363 const showDetails = showData as TMDBShowData; 364 - const episodePromises = showDetails.seasons.map(async (season) => { 365 - const seasonData = await get<TMDBSeason>( 366 - `/tv/${id}/season/${season.season_number}`, 367 - ); 368 - return seasonData.episodes.map((episode) => ({ 369 - id: episode.id, 370 - name: episode.name, 371 - episode_number: episode.episode_number, 372 - overview: episode.overview, 373 - still_path: episode.still_path, 374 - air_date: episode.air_date, 375 - season_number: season.season_number, 376 - })); 377 - }); 364 + const allEpisodesBySeason = new Array(showDetails.seasons.length); 365 + const seasonsQueue = showDetails.seasons.map((season, index) => ({ 366 + season, 367 + index, 368 + })); 369 + const concurrencyLimit = 5; 378 370 379 - const allEpisodes = (await Promise.all(episodePromises)).flat(); 371 + const workers = Array.from( 372 + { length: Math.min(concurrencyLimit, seasonsQueue.length) }, 373 + async () => { 374 + while (seasonsQueue.length > 0) { 375 + const item = seasonsQueue.shift(); 376 + if (!item) break; 377 + const { season, index } = item; 378 + const seasonData = await get<TMDBSeason>( 379 + `/tv/${id}/season/${season.season_number}`, 380 + ); 381 + allEpisodesBySeason[index] = seasonData.episodes.map((episode) => ({ 382 + id: episode.id, 383 + name: episode.name, 384 + episode_number: episode.episode_number, 385 + overview: episode.overview, 386 + still_path: episode.still_path, 387 + air_date: episode.air_date, 388 + season_number: season.season_number, 389 + })); 390 + } 391 + }, 392 + ); 393 + 394 + await Promise.all(workers); 395 + const allEpisodes = allEpisodesBySeason.flat(); 380 396 381 397 return { 382 398 ...showData,