mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-04-15 20:17:13 -04:00
Add caching
This commit is contained in:
@@ -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 });
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user