Limit concurrent cache lookups

This commit is contained in:
Szymon Nowakowski
2024-12-24 14:59:49 +01:00
parent 1786e1cac9
commit 57fbe476cb

View File

@@ -87,15 +87,19 @@ export const denormalizePiece = ({
Effect.flatMap(denormalizeSystemInformation),
);
const CacheSemaphore = Effect.unsafeMakeSemaphore(4);
export const userLookup = (userId: UserId) => pipe(
Effect.promise((signal) => client.user({ userId }).get({ fetch: { signal } })),
Effect.flatMap(mapResponse),
CacheSemaphore.withPermits(1),
);
export const pieceLookup = (pieceId: PieceId) => pipe(
Effect.promise((signal) => client.piece({ pieceId }).get({ fetch: { signal } })),
Effect.flatMap(mapResponse),
Effect.flatMap(denormalizePiece),
CacheSemaphore.withPermits(1),
);
export const userCache = Effect.runSync(Cache.make({