Skip to content

Commit 5b0bfc7

Browse files
authored
perf(ui): parallelize chunked chart download fetches (#2269)
1 parent 30d9990 commit 5b0bfc7

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

app/composables/useCharts.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
WeeklyDataPoint,
77
YearlyDataPoint,
88
} from '~/types/chart'
9+
import { mapWithConcurrency } from '#shared/utils/async'
910
import { fetchNpmDownloadsRange } from '~/utils/npm/api'
1011

1112
export type PackumentLikeForTime = {
@@ -256,12 +257,12 @@ async function fetchDailyRangeChunked(packageName: string, startIso: string, end
256257
return fetchDailyRangeCached(packageName, startIso, endIso)
257258
}
258259

259-
const all: DailyRawPoint[] = []
260-
261-
for (const range of ranges) {
262-
const part = await fetchDailyRangeCached(packageName, range.startIso, range.endIso)
263-
all.push(...part)
264-
}
260+
const parts = await mapWithConcurrency(
261+
ranges,
262+
range => fetchDailyRangeCached(packageName, range.startIso, range.endIso),
263+
10,
264+
)
265+
const all = parts.flat()
265266

266267
return mergeDailyPoints(all)
267268
}

0 commit comments

Comments
 (0)