Add caching

This commit is contained in:
MartinBraquet
2025-07-30 13:46:26 +02:00
parent 94476e330c
commit 43382f6406
2 changed files with 10 additions and 4 deletions

View File

@@ -4,6 +4,7 @@ import { NextResponse } from "next/server";
export async function GET() {
try {
// Get all interests from the database
const cacheStrategy = { swr: 60, ttl: 60 };
const interests = await prisma.interest.findMany({
select: {
id: true,
@@ -11,7 +12,8 @@ export async function GET() {
},
orderBy: {
name: 'asc'
}
},
cacheStrategy: cacheStrategy,
});
const causeAreas = await prisma.causeArea.findMany({
@@ -21,7 +23,8 @@ export async function GET() {
},
orderBy: {
name: 'asc'
}
},
cacheStrategy: cacheStrategy,
});
const connection = await prisma.connection.findMany({
@@ -31,7 +34,8 @@ export async function GET() {
},
orderBy: {
name: 'asc'
}
},
cacheStrategy: cacheStrategy,
});
return NextResponse.json({ interests, causeAreas, connection });

View File

@@ -10,7 +10,7 @@ export async function GET(request: Request) {
const causeAreas = url.searchParams.get("causeAreas")?.split(",").filter(Boolean) || [];
const searchQuery = url.searchParams.get("search") || "";
const profilesPerPage = 20;
const profilesPerPage = 100;
const offset = (page - 1) * profilesPerPage;
const session = await getSession();
@@ -84,6 +84,7 @@ export async function GET(request: Request) {
}
// Fetch paginated and filtered profiles
const cacheStrategy = { swr: 3600, ttl: 3600 };
const profiles = await prisma.user.findMany({
skip: offset,
take: profilesPerPage,
@@ -104,6 +105,7 @@ export async function GET(request: Request) {
},
},
},
cacheStrategy: cacheStrategy,
});
const totalProfiles = await prisma.user.count();