Skip to content

Commit 6691567

Browse files
committed
refactor fetchAdditionalUserData for promise.all (parallel fetches)
1 parent 0eca602 commit 6691567

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

app/(main)/league/all/page.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,19 @@ const Leagues = (): JSX.Element => {
4141
*/
4242
const fetchAdditionalUserData = async (): Promise<void> => {
4343
try {
44-
const promises = leagues.map((league) =>
44+
const entryPromises = leagues.map((league) =>
4545
getCurrentUserEntries(user.id, league.leagueId),
4646
);
47-
const entries = await Promise.all(promises);
48-
const currentWeek = await getGameWeek();
47+
const gameWeekPromise = getGameWeek();
48+
49+
const [entries, currentWeek] = await Promise.all([
50+
Promise.all(entryPromises),
51+
gameWeekPromise,
52+
]);
53+
4954
updateEntries(entries.flat());
5055
updateGameWeek(currentWeek);
5156
} catch (error) {
52-
console.error('Error fetching entries and game week:', error);
5357
throw new Error('Error fetching entries and game week');
5458
}
5559
};

0 commit comments

Comments
 (0)