A request-for-quote (RfQ) system for Gold Label Tech Ltd. Using Next.js with Prisma and MariaDB. Enhance on SEO with SSR and also include Admin page for managing the RfQs.
Challenge: Page Compile Speed is Slow
Challenge: Reusable Data with Cached Data Fetching
generateMetadata function provided by Next.js and the main Page function are running asynchronously, which means I need to call the database twice to get the items data: once for the metadata and once for the page. So I learned that I can use caching to store the data and reuse it in both functions, which also speeds up the page compile time!const getData = cache(async (productName: string) => {
const product = await prisma.product.findFirst({
where: { item_code: productName },
select: {
id: true,
item_code: true,
name: true,
youtube_link: true,
features: true,
spec: true,
product_types: { select: { id: true, name: true } },
categories: { select: { id: true, name: true } },
images: {
select: { id: true, url: true, order: true },
orderBy: { order: 'asc' },
},
attachments: {
select: { id: true, file_path: true, type: true },
orderBy: { order: 'asc' },
},
// attachments: true, // To select all fields
},
})
// Check if product is not found
if (!product) {
redirect(`/products/1`)
}
return { product_data: product }
})