From bbf0bd80e40c57b602d9d7373ddf15e963dede24 Mon Sep 17 00:00:00 2001 From: shadcn Date: Tue, 29 Nov 2022 17:22:54 +0400 Subject: [PATCH] feat: implement caching for user dashboard --- app/(dashboard)/dashboard/page.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/(dashboard)/dashboard/page.tsx b/app/(dashboard)/dashboard/page.tsx index 70e10ed..6551560 100644 --- a/app/(dashboard)/dashboard/page.tsx +++ b/app/(dashboard)/dashboard/page.tsx @@ -1,4 +1,5 @@ import { redirect } from "next/navigation" +import { cache } from "react" import { db } from "@/lib/db" import { getCurrentUser } from "@/lib/session" @@ -10,7 +11,7 @@ import { DashboardShell } from "@/components/dashboard/shell" import { PostItem } from "@/components/dashboard/post-item" import { EmptyPlaceholder } from "@/components/dashboard/empty-placeholder" -async function getPostsForUser(userId: User["id"]) { +const getPostsForUser = cache(async (userId: User["id"]) => { return await db.post.findMany({ where: { authorId: userId, @@ -25,7 +26,7 @@ async function getPostsForUser(userId: User["id"]) { updatedAt: "desc", }, }) -} +}) export default async function DashboardPage() { const user = await getCurrentUser()