mirror of
https://github.com/ahmadk953/tasko.git
synced 2025-04-30 18:59:37 +00:00
Added Redis for Caching and Started Database Query Caching Migration to Redis
This commit is contained in:
parent
f99360d9b9
commit
0f899cb34f
12 changed files with 260 additions and 632 deletions
|
@ -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,
|
||||
|
|
|
@ -2,6 +2,7 @@ import { auth } from '@clerk/nextjs/server';
|
|||
import { NextResponse } from 'next/server';
|
||||
|
||||
import { db } from '@/lib/db';
|
||||
import { unstable_cache } from 'next/cache';
|
||||
|
||||
export async function GET(
|
||||
req: Request,
|
||||
|
@ -16,27 +17,34 @@ export async function GET(
|
|||
status: 401,
|
||||
});
|
||||
|
||||
const card = await db.card.findUnique({
|
||||
where: {
|
||||
id: params.cardId,
|
||||
list: {
|
||||
board: {
|
||||
orgId,
|
||||
const getCard = unstable_cache(
|
||||
async () => {
|
||||
return await db.card.findUnique({
|
||||
where: {
|
||||
id: params.cardId,
|
||||
list: {
|
||||
board: {
|
||||
orgId,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
include: {
|
||||
list: {
|
||||
select: {
|
||||
title: true,
|
||||
include: {
|
||||
list: {
|
||||
select: {
|
||||
title: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
cacheStrategy: {
|
||||
ttl: 30,
|
||||
swr: 60,
|
||||
},
|
||||
});
|
||||
[`card-${params.cardId}`],
|
||||
{
|
||||
tags: [`card-${params.cardId}`],
|
||||
revalidate: false,
|
||||
}
|
||||
);
|
||||
|
||||
const card = await getCard();
|
||||
|
||||
return new NextResponse(JSON.stringify(card), {
|
||||
status: 200,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue