Skip to content

Commit

Permalink
feat: implement caching for user dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
shadcn committed Nov 29, 2022
1 parent 209cfae commit bbf0bd8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/(dashboard)/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { redirect } from "next/navigation"
import { cache } from "react"

import { db } from "@/lib/db"
import { getCurrentUser } from "@/lib/session"
Expand All @@ -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,
Expand All @@ -25,7 +26,7 @@ async function getPostsForUser(userId: User["id"]) {
updatedAt: "desc",
},
})
}
})

export default async function DashboardPage() {
const user = await getCurrentUser()
Expand Down

0 comments on commit bbf0bd8

Please sign in to comment.