Question related to Dynamic Tags
Answered
Arinji posted this in #help-forum
ArinjiOP
So i have this code
So i was wondering how i shld go about to revalidating this function with tags.
import {cookies} from "next/headers";
import {RequestCookie} from "next/dist/compiled/@edge-runtime/cookies";
import {getUserId} from "@/lib/getUserId";
import {query} from "@/lib/data";
import {BE_statusResponseBody, biolinkData} from "@/lib/types";
export async function getBiolinkStatus() {
const jwt: RequestCookie | undefined = cookies().get("token");
if (!jwt) {
return { status: 400, success: false, message: "No JWT provided" };
}
try {
const userId: number = await getUserId(jwt.value);
const queryBiolinkResult = await query(
`SELECT * FROM biolinks WHERE created_by=?`,
[userId]
);
const biolinks: Array<biolinkData> = Array.isArray(queryBiolinkResult) ? queryBiolinkResult : [];
const body: BE_statusResponseBody = {
success: true,
premium: biolinks[0].premium === "1",
verified: biolinks[0].verified === "1",
}
return { status: 200, success: true, message: "Successfully fetched biolink status", body: body };
} catch (error) {
console.error(error)
return { status: 500, success: false, message: "Internal server error" };
}
}So i was wondering how i shld go about to revalidating this function with tags.
Answered by DirtyCajunRice | AppDir
you dont want to cache database calls (generally)
9 Replies
ArinjiOP
Basically i want to be able to revalidate this by like a submit api
and make it so when i revalidate this its only revalidated for one person, soo the tags would be dynamic with the userid
Yeah it would work. just watch your vercel logs to make sure it doesnt get crazy expensive
@DirtyCajunRice | AppDir Yeah it would work. just watch your vercel logs to make sure it doesnt get crazy expensive
ArinjiOP
but we dont use the fetch api directly in the function since its mysql, is there any other way to revalidate?
also the link is general so smthn like revalidatePage wont work as well coz the page dosent have a unique id
@Arinji but we dont use the fetch api directly in the function since its mysql, is there any other way to revalidate?
you dont want to cache database calls (generally)
Answer
ArinjiOP
true true, well eh its a pretty fast query so we shldnt have to wrry abt caching
thanks for your help doe dude :DDDDDDDD