perf(map): chunk album fetching to prevent OOM errors (#138)

Replaced the unbounded `Promise.all` in `getMapData` with a chunked
fetching approach. This prevents Out of Memory crashes by limiting
the concurrent fetching of large arrays of assets to chunks of 10.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This commit is contained in:
Ralksta
2026-04-24 22:12:45 +02:00
committed by GitHub
parent f18d9ae3d9
commit 56f0305763
2 changed files with 12 additions and 1 deletions

View File

@@ -34,7 +34,15 @@ export async function getMapData(): Promise<MapLocation[]> {
}
// Fetch full album data (with assets) for each
const fullAlbums = await Promise.all(albums.map((a) => immich.getAlbum(a.id)));
// Process in chunks of 10 to balance network speed and prevent Out of Memory (OOM)
// crashes from fetching thousands of assets simultaneously.
const fullAlbums: (Awaited<ReturnType<typeof immich.getAlbum>> | null)[] = [];
const chunkSize = 10;
for (let i = 0; i < albums.length; i += chunkSize) {
const chunk = albums.slice(i, i + chunkSize);
const chunkResults = await Promise.all(chunk.map((a) => immich.getAlbum(a.id)));
fullAlbums.push(...chunkResults);
}
// Bucket assets by city+country
const buckets = new Map<