chore: snapshot before performance optimization
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import prisma from '@/lib/prisma'
|
||||
import { auth } from '@/auth'
|
||||
import { sendEmail } from '@/lib/mail'
|
||||
import { revalidateTag } from 'next/cache'
|
||||
|
||||
async function checkAdmin() {
|
||||
const session = await auth()
|
||||
@@ -29,11 +30,9 @@ export async function testSMTP() {
|
||||
|
||||
export async function getSystemConfig() {
|
||||
await checkAdmin()
|
||||
const configs = await prisma.systemConfig.findMany()
|
||||
return configs.reduce((acc, conf) => {
|
||||
acc[conf.key] = conf.value
|
||||
return acc
|
||||
}, {} as Record<string, string>)
|
||||
// Reuse the cached version from lib/config
|
||||
const { getSystemConfig: getCachedConfig } = await import('@/lib/config')
|
||||
return getCachedConfig()
|
||||
}
|
||||
|
||||
export async function updateSystemConfig(data: Record<string, string>) {
|
||||
@@ -45,8 +44,6 @@ export async function updateSystemConfig(data: Record<string, string>) {
|
||||
Object.entries(data).filter(([key, value]) => value !== '' && value !== null && value !== undefined)
|
||||
)
|
||||
|
||||
|
||||
|
||||
const operations = Object.entries(filteredData).map(([key, value]) =>
|
||||
prisma.systemConfig.upsert({
|
||||
where: { key },
|
||||
@@ -56,6 +53,10 @@ export async function updateSystemConfig(data: Record<string, string>) {
|
||||
)
|
||||
|
||||
await prisma.$transaction(operations)
|
||||
|
||||
// Invalidate cache after update
|
||||
revalidateTag('system-config', '/settings')
|
||||
|
||||
return { success: true }
|
||||
} catch (error) {
|
||||
console.error('Failed to update settings:', error)
|
||||
|
||||
Reference in New Issue
Block a user