Finished Adding Chacing

This commit is contained in:
Ahmad 2025-01-19 01:36:59 -05:00
parent be70b88925
commit e0ba56659f
No known key found for this signature in database
GPG key ID: 8FD8A93530D182BF
2 changed files with 19 additions and 7 deletions

View file

@ -1,7 +1,7 @@
'use server'; 'use server';
import { auth } from '@clerk/nextjs/server'; import { auth } from '@clerk/nextjs/server';
import { revalidatePath } from 'next/cache'; import { revalidatePath, revalidateTag } from 'next/cache';
import { ACTION, ENTITY_TYPE } from '@prisma/client'; import { ACTION, ENTITY_TYPE } from '@prisma/client';
import { db } from '@/lib/db'; import { db } from '@/lib/db';
@ -74,6 +74,7 @@ const handler = async (data: InputType): Promise<ReturnType> => {
}; };
} }
revalidateTag(`board-${id}`);
revalidatePath(`/board/${id}`); revalidatePath(`/board/${id}`);
return { data: board }; return { data: board };
}; };

View file

@ -4,6 +4,7 @@ import { notFound, redirect } from 'next/navigation';
import { db } from '@/lib/db'; import { db } from '@/lib/db';
import { BoardNavbar } from './_components/board-navbar'; import { BoardNavbar } from './_components/board-navbar';
import { BoardLiveblocks } from './_components/board-liveblocks'; import { BoardLiveblocks } from './_components/board-liveblocks';
import { unstable_cache } from 'next/cache';
export async function generateMetadata(props: { export async function generateMetadata(props: {
params: Promise<{ boardId: string }>; params: Promise<{ boardId: string }>;
@ -37,13 +38,23 @@ const BoardIdLayout = async (props: {
if (!orgId) redirect('/select-org'); if (!orgId) redirect('/select-org');
const board = await db.board.findUnique({ const getBoard = unstable_cache(
async () => {
return await db.board.findUnique({
where: { where: {
id: params.boardId, id: params.boardId,
orgId, orgId,
}, },
cacheStrategy: { ttl: 30, swr: 60 },
}); });
},
[`board-${params.boardId}`],
{
tags: [`board-${params.boardId}`],
revalidate: false,
}
);
const board = await getBoard();
if (!board) notFound(); if (!board) notFound();