From a71f01ea3ab9aa3f2a55599236dcd26ab61e5771 Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Mon, 22 May 2023 13:37:56 +0200 Subject: [PATCH 1/2] add isr --- app/sidebar.tsx | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/app/sidebar.tsx b/app/sidebar.tsx index a28d27cb..c31196ec 100644 --- a/app/sidebar.tsx +++ b/app/sidebar.tsx @@ -6,6 +6,7 @@ import { type Session } from "@/lib/session/types"; import { cn } from "@/lib/utils"; import { Plus } from "lucide-react"; import Link from "next/link"; +import { unstable_cache } from "next/cache"; import { SidebarItem } from "./sidebar-item"; export interface SidebarProps { @@ -57,15 +58,25 @@ export function Sidebar({ session, newChat }: SidebarProps) { Sidebar.displayName = "Sidebar"; async function SidebarList({ session }: { session?: Session }) { - const chats = await prisma.chat.findMany({ - where: { - // This is for debugging, need to add scope to the query later - // userId: session?.user.id, - }, - orderBy: { - updatedAt: "desc", - }, - }); + const chats = ( + await unstable_cache( + () => + prisma.chat.findMany({ + where: { + // This is for debugging, need to add scope to the query later + // userId: session?.user.id, + }, + orderBy: { + updatedAt: "desc", + }, + }), + [session?.user.id || ""], + { + revalidate: 3600, + } + ) + )(); + return chats.map((c) => ( )); From 9b825542d71988ac88c650efd56a23c8388db343 Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Mon, 22 May 2023 13:40:47 +0200 Subject: [PATCH 2/2] fix --- app/sidebar.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/sidebar.tsx b/app/sidebar.tsx index c31196ec..e2379f3b 100644 --- a/app/sidebar.tsx +++ b/app/sidebar.tsx @@ -58,7 +58,7 @@ export function Sidebar({ session, newChat }: SidebarProps) { Sidebar.displayName = "Sidebar"; async function SidebarList({ session }: { session?: Session }) { - const chats = ( + const chats = await ( await unstable_cache( () => prisma.chat.findMany({