Add repertoire list page
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type * as Db from "backend/database";
|
||||
import { AttachmentId, PieceId, UserId } from "common";
|
||||
import { AttachmentId, PieceId, RepertoireId, UserId } from "common";
|
||||
import { Cache, Duration, Effect, Option, pipe } from "effect";
|
||||
import { client, mapResponse } from "./client";
|
||||
|
||||
@@ -87,8 +87,36 @@ export const denormalizePiece = ({
|
||||
Effect.flatMap(denormalizeSystemInformation),
|
||||
);
|
||||
|
||||
export const denormalizeRepertoireEntry = ({
|
||||
pieceId,
|
||||
...rest
|
||||
}: Db.RepertoireEntry) => pipe(
|
||||
Effect.all({
|
||||
piece: Effect.uninterruptible(pieceCache.get(pieceId)),
|
||||
}, { concurrency: "unbounded" }),
|
||||
Effect.map((entry) => Object.freeze({
|
||||
...rest,
|
||||
...entry,
|
||||
})),
|
||||
);
|
||||
|
||||
export const denormalizeRepertoire = ({
|
||||
entries,
|
||||
...rest
|
||||
}: Db.Repertoire & { entries: Db.RepertoireEntry[] }) => pipe(
|
||||
Effect.all({
|
||||
entries: Effect.all(entries.map(denormalizeRepertoireEntry), { concurrency: "unbounded" }),
|
||||
}, { concurrency: "unbounded" }),
|
||||
Effect.map((repertoire) => Object.freeze({
|
||||
...rest,
|
||||
...repertoire,
|
||||
})),
|
||||
Effect.flatMap(denormalizeSystemInformation),
|
||||
);
|
||||
|
||||
const UserSemaphore = Effect.unsafeMakeSemaphore(1);
|
||||
const CacheSemaphore = Effect.unsafeMakeSemaphore(4);
|
||||
const RepertoireSemaphore = Effect.unsafeMakeSemaphore(1);
|
||||
|
||||
export const userLookup = (userId: UserId) => pipe(
|
||||
Effect.promise((signal) => client.user({ userId }).get({ fetch: { signal } })),
|
||||
@@ -103,6 +131,13 @@ export const pieceLookup = (pieceId: PieceId) => pipe(
|
||||
CacheSemaphore.withPermits(1),
|
||||
);
|
||||
|
||||
export const repertoireLookup = (repertoireId: RepertoireId) => pipe(
|
||||
Effect.promise((signal) => client.repertoire({ repertoireId }).get({ fetch: { signal } })),
|
||||
Effect.flatMap(mapResponse),
|
||||
Effect.flatMap(denormalizeRepertoire),
|
||||
RepertoireSemaphore.withPermits(1),
|
||||
);
|
||||
|
||||
export const userCache = Effect.runSync(Cache.make({
|
||||
capacity: Infinity,
|
||||
timeToLive: Duration.days(1),
|
||||
@@ -114,3 +149,9 @@ export const pieceCache = Effect.runSync(Cache.make({
|
||||
timeToLive: Duration.days(1),
|
||||
lookup: pieceLookup,
|
||||
}));
|
||||
|
||||
export const repertoireCache = Effect.runSync(Cache.make({
|
||||
capacity: Infinity,
|
||||
timeToLive: Duration.days(1),
|
||||
lookup: repertoireLookup,
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user