mirror of
https://github.com/p-stream/p-stream.git
synced 2026-04-20 05:22:05 +00:00
load all movie lists from trakt one after another
This commit is contained in:
parent
65246b8be9
commit
a7889d568b
2 changed files with 24 additions and 19 deletions
|
|
@ -227,27 +227,32 @@ export const getMovieDetailsForIds = async (
|
|||
|
||||
// Process in smaller batches to avoid overwhelming the API
|
||||
const batchSize = 10;
|
||||
const batchPromises: Promise<TMDBMovieData[]>[] = [];
|
||||
|
||||
for (let i = 0; i < limitedIds.length; i += batchSize) {
|
||||
const batch = limitedIds.slice(i, i + batchSize);
|
||||
const batchPromises = batch.map(async (id) => {
|
||||
try {
|
||||
const details = await getMediaDetails(
|
||||
id.toString(),
|
||||
TMDBContentTypes.MOVIE,
|
||||
);
|
||||
return details as TMDBMovieData;
|
||||
} catch (error) {
|
||||
console.error(`Failed to fetch movie details for ID ${id}:`, error);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
const batchResults = await Promise.all(batchPromises);
|
||||
const validResults = batchResults.filter(
|
||||
(result): result is TMDBMovieData => result !== null,
|
||||
const batchPromise = Promise.all(
|
||||
batch.map(async (id) => {
|
||||
try {
|
||||
const details = await getMediaDetails(
|
||||
id.toString(),
|
||||
TMDBContentTypes.MOVIE,
|
||||
);
|
||||
return details as TMDBMovieData;
|
||||
} catch (error) {
|
||||
console.error(`Failed to fetch movie details for ID ${id}:`, error);
|
||||
return null;
|
||||
}
|
||||
}),
|
||||
).then((batchResults) =>
|
||||
batchResults.filter((result): result is TMDBMovieData => result !== null),
|
||||
);
|
||||
movieDetails.push(...validResults);
|
||||
batchPromises.push(batchPromise);
|
||||
}
|
||||
|
||||
// Process all batches in parallel
|
||||
const batchResults = await Promise.all(batchPromises);
|
||||
movieDetails.push(...batchResults.flat());
|
||||
|
||||
return movieDetails;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -38,13 +38,14 @@ export function DiscoverMore() {
|
|||
const lists = await getCuratedMovieLists();
|
||||
setCuratedLists(lists);
|
||||
|
||||
// Fetch movie details for each list
|
||||
// Fetch movie details for each list one after another
|
||||
const details: { [listSlug: string]: TMDBMovieData[] } = {};
|
||||
for (const list of lists) {
|
||||
try {
|
||||
const movies = await getMovieDetailsForIds(list.tmdbIds, 50);
|
||||
if (movies.length > 0) {
|
||||
details[list.listSlug] = movies;
|
||||
setMovieDetails({ ...details });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(
|
||||
|
|
@ -53,7 +54,6 @@ export function DiscoverMore() {
|
|||
);
|
||||
}
|
||||
}
|
||||
setMovieDetails(details);
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch curated lists:", error);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue