Spaces:
Configuration error
Configuration error
perf: add ISR revalidation (30s) to explore page
Browse files- src/app/explore/page.tsx +47 -43
src/app/explore/page.tsx
CHANGED
|
@@ -2,13 +2,13 @@ import { Suspense } from "react"
|
|
| 2 |
import { Metadata } from "next"
|
| 3 |
import prisma from "@/lib/prisma"
|
| 4 |
import { ExploreClient } from "@/components/explore/explore-client"
|
| 5 |
-
import { Badge } from "@/components/ui/badge"
|
| 6 |
import { Loader2 } from "lucide-react"
|
| 7 |
import { generateSEO } from "@/lib/seo"
|
| 8 |
|
| 9 |
const BASE_URL = process.env.NEXT_PUBLIC_APP_URL || 'https://open-prompt.netlify.app'
|
| 10 |
|
| 11 |
-
|
|
|
|
| 12 |
|
| 13 |
export const metadata: Metadata = generateSEO({
|
| 14 |
title: "Explore AI Prompts | OpenPrompt",
|
|
@@ -18,56 +18,60 @@ export const metadata: Metadata = generateSEO({
|
|
| 18 |
}) as Metadata
|
| 19 |
|
| 20 |
async function getInitialPrompts(category?: string, search?: string, sort?: string) {
|
| 21 |
-
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
|
| 37 |
-
|
| 38 |
-
orderBy.push({ id: 'desc' })
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
| 63 |
},
|
| 64 |
},
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
})
|
| 69 |
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
}
|
| 72 |
|
| 73 |
interface ExplorePageProps {
|
|
|
|
| 2 |
import { Metadata } from "next"
|
| 3 |
import prisma from "@/lib/prisma"
|
| 4 |
import { ExploreClient } from "@/components/explore/explore-client"
|
|
|
|
| 5 |
import { Loader2 } from "lucide-react"
|
| 6 |
import { generateSEO } from "@/lib/seo"
|
| 7 |
|
| 8 |
const BASE_URL = process.env.NEXT_PUBLIC_APP_URL || 'https://open-prompt.netlify.app'
|
| 9 |
|
| 10 |
+
// Revalidate every 30 seconds instead of force-dynamic
|
| 11 |
+
export const revalidate = 30
|
| 12 |
|
| 13 |
export const metadata: Metadata = generateSEO({
|
| 14 |
title: "Explore AI Prompts | OpenPrompt",
|
|
|
|
| 18 |
}) as Metadata
|
| 19 |
|
| 20 |
async function getInitialPrompts(category?: string, search?: string, sort?: string) {
|
| 21 |
+
try {
|
| 22 |
+
const orderBy: Record<string, 'asc' | 'desc'>[] = []
|
| 23 |
|
| 24 |
+
switch (sort) {
|
| 25 |
+
case 'recent':
|
| 26 |
+
orderBy.push({ createdAt: 'desc' })
|
| 27 |
+
break
|
| 28 |
+
case 'stars':
|
| 29 |
+
orderBy.push({ starsCount: 'desc' })
|
| 30 |
+
break
|
| 31 |
+
case 'runs':
|
| 32 |
+
orderBy.push({ totalRuns: 'desc' })
|
| 33 |
+
break
|
| 34 |
+
default:
|
| 35 |
+
orderBy.push({ totalRuns: 'desc' })
|
| 36 |
+
}
|
| 37 |
|
| 38 |
+
orderBy.push({ id: 'desc' })
|
|
|
|
| 39 |
|
| 40 |
+
const where: Record<string, unknown> = {
|
| 41 |
+
visibility: 'public',
|
| 42 |
+
}
|
| 43 |
|
| 44 |
+
if (category) {
|
| 45 |
+
where.category = category
|
| 46 |
+
}
|
| 47 |
|
| 48 |
+
if (search) {
|
| 49 |
+
where.OR = [
|
| 50 |
+
{ title: { contains: search, mode: 'insensitive' } },
|
| 51 |
+
{ description: { contains: search, mode: 'insensitive' } },
|
| 52 |
+
]
|
| 53 |
+
}
|
| 54 |
|
| 55 |
+
const prompts = await prisma.prompt.findMany({
|
| 56 |
+
where,
|
| 57 |
+
include: {
|
| 58 |
+
creator: {
|
| 59 |
+
select: {
|
| 60 |
+
name: true,
|
| 61 |
+
username: true,
|
| 62 |
+
image: true,
|
| 63 |
+
},
|
| 64 |
},
|
| 65 |
},
|
| 66 |
+
orderBy,
|
| 67 |
+
take: 12,
|
| 68 |
+
})
|
|
|
|
| 69 |
|
| 70 |
+
return prompts
|
| 71 |
+
} catch (error) {
|
| 72 |
+
console.error('Explore page data fetch error:', error)
|
| 73 |
+
return []
|
| 74 |
+
}
|
| 75 |
}
|
| 76 |
|
| 77 |
interface ExplorePageProps {
|