mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-03-06 15:59:47 -05:00
Add cache tags
This commit is contained in:
@@ -4,7 +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 cacheStrategy = { swr: 60, ttl: 60, tags: ["interests"] };
|
||||
const interests = await prisma.interest.findMany({
|
||||
select: {
|
||||
id: true,
|
||||
|
||||
@@ -9,6 +9,7 @@ export async function GET(
|
||||
const params = await context.params;
|
||||
const { id } = params;
|
||||
|
||||
const cacheStrategy = { swr: 3600, ttl: 3600, tags: ["profiles/[id]"] };
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { id },
|
||||
select: {
|
||||
@@ -26,6 +27,7 @@ export async function GET(
|
||||
},
|
||||
},
|
||||
},
|
||||
cacheStrategy: cacheStrategy,
|
||||
});
|
||||
|
||||
// If user not found, return 404
|
||||
|
||||
@@ -84,7 +84,7 @@ export async function GET(request: Request) {
|
||||
}
|
||||
|
||||
// Fetch paginated and filtered profiles
|
||||
const cacheStrategy = { swr: 3600, ttl: 3600 };
|
||||
const cacheStrategy = { swr: 3600, ttl: 3600 , tags: ["profiles"]};
|
||||
const profiles = await prisma.user.findMany({
|
||||
skip: offset,
|
||||
take: profilesPerPage,
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import {prisma} from "@/lib/server/prisma";
|
||||
import {PrismaClient} from "@prisma/client";
|
||||
|
||||
// Cannot import from prisma.ts as we are outside the server
|
||||
const prisma = new PrismaClient({log: ['query']})
|
||||
|
||||
|
||||
async function main() {
|
||||
|
||||
// Create some interests and cause areas
|
||||
await prisma.interest.createMany({
|
||||
data: [
|
||||
@@ -31,17 +35,25 @@ async function main() {
|
||||
skipDuplicates: true,
|
||||
});
|
||||
|
||||
const names = [
|
||||
'Alice Wonderland',
|
||||
'Bob the Builder',
|
||||
'Emily McConaughey',
|
||||
'Alex Hepburn',
|
||||
'Laurent Golden'
|
||||
]
|
||||
|
||||
// Get actual Interest & CauseArea objects
|
||||
const allInterests = await prisma.interest.findMany();
|
||||
const allCauseAreas = await prisma.causeArea.findMany();
|
||||
const allConnections = await prisma.connection.findMany();
|
||||
|
||||
// Create mock users
|
||||
for (let i = 1; i <= 5; i++) {
|
||||
for (let i = 0; i < 5; i++) {
|
||||
const user = await prisma.user.create({
|
||||
data: {
|
||||
email: `user${i}@bayesbond.com`,
|
||||
name: `User ${i}`,
|
||||
email: `user${i+1}@bayesbond.com`,
|
||||
name: names[i],
|
||||
image: null,
|
||||
profile: {
|
||||
create: {
|
||||
|
||||
Reference in New Issue
Block a user