Reimplement cache more lol

This commit is contained in:
2025-10-10 14:54:42 +02:00
parent a199b104ad
commit 6ea21aa0f1
8 changed files with 224 additions and 130 deletions

View File

@@ -7,10 +7,9 @@ import { Label } from "@/components/ui/label";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import { useCache } from "@/hooks/useCache";
import { useLoading } from "@/hooks/useLoading";
import { Updater } from "@/hooks/useStore";
import { authors, created, DEBOUNCE, modified, SAVE_DELAY } from "@/snippets";
import clsx from "clsx";
import { PieceId } from "common";
import { PieceId, Updater } from "common";
import * as Body from "common/Body";
import { getMediaTypeForFilename } from "common/MediaType";
import { Array, Cause, Effect, Fiber, Iterable, Match, Option, Order, pipe, Predicate, Scope, SortedMap } from "effect";
@@ -27,7 +26,7 @@ export function Pieces() {
const debounce = useRef(Effect.void);
const { isLoading, error, data: pieceIds } = useLoading(Effect.gen(function* () {
const { isLoading, error, data: pieceIds, refresh } = useLoading(Effect.gen(function* () {
yield* debounce.current;
const data = yield* client.queryPieces({
name: name !== "" ? Option.some(name) : Option.none(),
@@ -55,7 +54,7 @@ export function Pieces() {
<Import />Importuj utwory
</Button>
</DialogTrigger>
<ImportPiecesDialogContent setDialogOpen={setImportDialogOpen} />
<ImportPiecesDialogContent setDialogOpen={setImportDialogOpen} refresh={refresh} />
</Dialog>
<Input
className="w-[32ch]"
@@ -197,7 +196,7 @@ function AddPieceDialogContent() {
arranger: arranger.length > 0 ? Option.some(arranger) : Option.none(),
}),
Effect.flatMap(denormalizePiece),
Effect.tap((piece) => Effect.sync(() => pieceCache.setFulfilledSucceed(piece.pieceId, piece))),
Effect.tap((piece) => pieceCache.create(piece.pieceId, piece)),
);
navigate(pieceId);
@@ -260,6 +259,7 @@ function AddPieceDialogContent() {
namespace ImportPiecesDialogContent {
export interface Props {
readonly setDialogOpen: Updater<boolean>;
readonly refresh: Effect.Effect<void>;
}
}
@@ -358,12 +358,16 @@ function ImportPiecesDialogContent(props: ImportPiecesDialogContent.Props) {
yield* pipe(
{ ...piece, attachments },
denormalizePiece,
Effect.tap((piece) => Effect.sync(() => pieceCache.setFulfilledSucceed(piece.pieceId, piece))),
Effect.tap((piece) => pieceCache.create(piece.pieceId, piece)),
);
setFiles(SortedMap.remove(name));
})),
Effect.allWith({ concurrency: "unbounded" }),
);
yield* props.refresh;
props.setDialogOpen(false);
}));
}).pipe(Effect.runPromise);