refactor(route): rename [id] to [problemId] in problems route

This commit is contained in:
cfngc4594 2025-05-07 14:47:20 +08:00
parent 1db666a2ab
commit b67b13d7bf
6 changed files with 36 additions and 28 deletions

View File

@ -3,16 +3,16 @@ import { ProblemHeader } from "@/features/problems/components/problem-header";
interface ProblemLayoutProps { interface ProblemLayoutProps {
children: React.ReactNode; children: React.ReactNode;
params: Promise<{ id: string }>; params: Promise<{ problemId: string }>;
} }
export default async function ProblemLayout({ export default async function ProblemLayout({
children, children,
params, params,
}: ProblemLayoutProps) { }: ProblemLayoutProps) {
const { id } = await params; const { problemId } = await params;
if (!id) { if (!problemId) {
return notFound(); return notFound();
} }

View File

@ -4,11 +4,11 @@ import { MdxRenderer } from "@/components/content/mdx-renderer";
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"; import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
interface DescriptionContentProps { interface DescriptionContentProps {
id: string; problemId: string;
} }
const DescriptionContent = async ({ id }: DescriptionContentProps) => { const DescriptionContent = async ({ problemId }: DescriptionContentProps) => {
const problem = await getCachedProblem(id); const problem = await getCachedProblem(problemId);
return ( return (
<ScrollArea className="h-full"> <ScrollArea className="h-full">

View File

@ -5,16 +5,16 @@ import {
} from "@/features/problems/description/components/content"; } from "@/features/problems/description/components/content";
interface DescriptionPanelProps { interface DescriptionPanelProps {
id: string; problemId: string;
} }
const DescriptionPanel = ({ id }: DescriptionPanelProps) => { const DescriptionPanel = ({ problemId }: DescriptionPanelProps) => {
return ( return (
<div className="h-full flex flex-col border border-t-0 border-muted rounded-b-3xl bg-background overflow-hidden"> <div className="h-full flex flex-col border border-t-0 border-muted rounded-b-3xl bg-background overflow-hidden">
<div className="relative flex-1"> <div className="relative flex-1">
<div className="absolute h-full w-full"> <div className="absolute h-full w-full">
<Suspense fallback={<DescriptionContentSkeleton />}> <Suspense fallback={<DescriptionContentSkeleton />}>
<DescriptionContent id={id} /> <DescriptionContent problemId={problemId} />
</Suspense> </Suspense>
</div> </div>
</div> </div>

View File

@ -4,11 +4,11 @@ import { MdxRenderer } from "@/components/content/mdx-renderer";
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"; import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
interface SolutionContentProps { interface SolutionContentProps {
id: string; problemId: string;
} }
const SolutionContent = async ({ id }: SolutionContentProps) => { const SolutionContent = async ({ problemId }: SolutionContentProps) => {
const problem = await getCachedProblem(id); const problem = await getCachedProblem(problemId);
return ( return (
<ScrollArea className="h-full"> <ScrollArea className="h-full">

View File

@ -5,16 +5,16 @@ import {
} from "@/features/problems/solution/components/content"; } from "@/features/problems/solution/components/content";
interface SolutionPanelProps { interface SolutionPanelProps {
id: string; problemId: string;
} }
const SolutionPanel = ({ id }: SolutionPanelProps) => { const SolutionPanel = ({ problemId }: SolutionPanelProps) => {
return ( return (
<div className="h-full flex flex-col border border-t-0 border-muted rounded-b-3xl bg-background overflow-hidden"> <div className="h-full flex flex-col border border-t-0 border-muted rounded-b-3xl bg-background overflow-hidden">
<div className="relative flex-1"> <div className="relative flex-1">
<div className="absolute h-full w-full"> <div className="absolute h-full w-full">
<Suspense fallback={<SolutionContentSkeleton />}> <Suspense fallback={<SolutionContentSkeleton />}>
<SolutionContent id={id} /> <SolutionContent problemId={problemId} />
</Suspense> </Suspense>
</div> </div>
</div> </div>

View File

@ -61,52 +61,60 @@ export const getCachedProblems = cache(
) )
); );
const getProblem = async (id: string) => { const getProblem = async (problemId: string) => {
const startTime = Date.now(); const startTime = Date.now();
log.debug({ id }, "Fetching single problem"); log.debug({ problemId }, "Fetching single problem");
try { try {
const problem = await prisma.problem.findUnique({ where: { id } }); const problem = await prisma.problem.findUnique({
where: { id: problemId },
});
if (problem) { if (problem) {
log.debug({ id, durationMs: Date.now() - startTime }, "Problem found"); log.debug(
{ problemId, durationMs: Date.now() - startTime },
"Problem found"
);
} else { } else {
log.warn({ id, durationMs: Date.now() - startTime }, "Problem not found"); log.warn(
{ problemId, durationMs: Date.now() - startTime },
"Problem not found"
);
} }
return problem; return problem;
} catch (error) { } catch (error) {
log.error( log.error(
{ id, durationMs: Date.now() - startTime, error }, { problemId, durationMs: Date.now() - startTime, error },
"Failed to fetch problem" "Failed to fetch problem"
); );
throw error; throw error;
} }
}; };
export const getCachedProblem = cache((id: string) => export const getCachedProblem = cache((problemId: string) =>
unstable_cache( unstable_cache(
async () => { async () => {
const startTime = Date.now(); const startTime = Date.now();
log.debug( log.debug(
{ id }, { problemId },
"Calling getProblemCached (expect cache hit if warmed)" "Calling getProblemCached (expect cache hit if warmed)"
); );
try { try {
const result = await getProblem(id); const result = await getProblem(problemId);
log.info( log.info(
{ id, durationMs: Date.now() - startTime }, { problemId, durationMs: Date.now() - startTime },
"getProblemCached finished" "getProblemCached finished"
); );
return result; return result;
} catch (error) { } catch (error) {
log.error( log.error(
{ id, durationMs: Date.now() - startTime, error }, { problemId, durationMs: Date.now() - startTime, error },
"getProblemCached failed" "getProblemCached failed"
); );
throw error; throw error;
} }
}, },
["getProblem", id], ["getProblem", problemId],
{ {
tags: [`problem-${id}`], tags: [`problem-${problemId}`],
} }
)() )()
); );