Added Redis for Caching and Started Database Query Caching Migration to Redis

This commit is contained in:
Ahmad 2025-01-18 19:14:19 -05:00
parent f99360d9b9
commit 0f899cb34f
No known key found for this signature in database
GPG key ID: 8FD8A93530D182BF
12 changed files with 260 additions and 632 deletions

View file

@ -1,6 +1,7 @@
import { auth } from '@clerk/nextjs/server';
import { ENTITY_TYPE } from '@prisma/client';
import { NextResponse } from 'next/server';
import { unstable_cache } from 'next/cache';
import { db } from '@/lib/db';
@ -17,21 +18,28 @@ export async function GET(
status: 401,
});
const auditLogs = await db.auditLog.findMany({
where: {
orgId,
entityId: params.cardId,
entityType: ENTITY_TYPE.CARD,
const getAuditLogs = unstable_cache(
async () => {
return await db.auditLog.findMany({
where: {
orgId,
entityId: params.cardId,
entityType: ENTITY_TYPE.CARD,
},
orderBy: {
createdAt: 'desc',
},
take: 3,
});
},
orderBy: {
createdAt: 'desc',
},
take: 3,
cacheStrategy: {
ttl: 30,
swr: 60,
},
});
[`card-logs-${params.cardId}`],
{
tags: [`card-logs-${params.cardId}`],
revalidate: false,
}
);
const auditLogs = await getAuditLogs();
return new NextResponse(JSON.stringify(auditLogs), {
status: 200,