This commit is contained in:
Shu Ding 2023-05-22 13:37:56 +02:00
parent b33601d742
commit a71f01ea3a
No known key found for this signature in database
GPG key ID: B84C6E25F5FEA16B

View file

@ -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,7 +58,10 @@ export function Sidebar({ session, newChat }: SidebarProps) {
Sidebar.displayName = "Sidebar";
async function SidebarList({ session }: { session?: Session }) {
const chats = await prisma.chat.findMany({
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,
@ -65,7 +69,14 @@ async function SidebarList({ session }: { session?: Session }) {
orderBy: {
updatedAt: "desc",
},
});
}),
[session?.user.id || ""],
{
revalidate: 3600,
}
)
)();
return chats.map((c) => (
<SidebarItem key={c.id} title={c.title} href={`/chat/${c.id}`} id={c.id} />
));