performance optimizations and database indexing
This commit is contained in:
28
pages/api/admin/optimize.ts
Normal file
28
pages/api/admin/optimize.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next"
|
||||
import { optimizeDatabase, getDatabaseStats } from "../../../lib/db-optimizations"
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (req.method === "POST") {
|
||||
try {
|
||||
await optimizeDatabase()
|
||||
res.json({
|
||||
success: true,
|
||||
message: "Database optimized successfully",
|
||||
optimized_at: new Date().toISOString()
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Optimization error:', error)
|
||||
res.status(500).json({ error: "Optimization failed" })
|
||||
}
|
||||
} else if (req.method === "GET") {
|
||||
try {
|
||||
const stats = await getDatabaseStats()
|
||||
res.json(stats)
|
||||
} catch (error) {
|
||||
console.error('Stats error:', error)
|
||||
res.status(500).json({ error: "Failed to get database stats" })
|
||||
}
|
||||
} else {
|
||||
res.status(405).json({ error: "Method not allowed" })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user