chore: snapshot before performance optimization

This commit is contained in:
Sepehr Ramezani
2026-04-17 21:14:43 +02:00
parent b6a548acd8
commit 2eceb32fd4
95 changed files with 4357 additions and 1942 deletions

View File

@@ -1,41 +1,50 @@
import prisma from './prisma';
import prisma from './prisma'
import { unstable_cache } from 'next/cache'
const getCachedSystemConfig = unstable_cache(
async () => {
try {
const configs = await prisma.systemConfig.findMany()
return configs.reduce((acc, conf) => {
acc[conf.key] = conf.value
return acc
}, {} as Record<string, string>)
} catch (e) {
console.error('Failed to load system config from DB:', e)
return {}
}
},
['system-config'],
{ tags: ['system-config'] }
)
export async function getSystemConfig() {
try {
const configs = await prisma.systemConfig.findMany();
return configs.reduce((acc, conf) => {
acc[conf.key] = conf.value;
return acc;
}, {} as Record<string, string>);
} catch (e) {
console.error('Failed to load system config from DB:', e);
return {};
}
return getCachedSystemConfig()
}
/**
* Get a config value with a default fallback
*/
export async function getConfigValue(key: string, defaultValue: string = ''): Promise<string> {
const config = await getSystemConfig();
return config[key] || defaultValue;
const config = await getSystemConfig()
return config[key] || defaultValue
}
/**
* Get a numeric config value with a default fallback
*/
export async function getConfigNumber(key: string, defaultValue: number): Promise<number> {
const value = await getConfigValue(key, String(defaultValue));
const num = parseFloat(value);
return isNaN(num) ? defaultValue : num;
const value = await getConfigValue(key, String(defaultValue))
const num = parseFloat(value)
return isNaN(num) ? defaultValue : num
}
/**
* Get a boolean config value with a default fallback
*/
export async function getConfigBoolean(key: string, defaultValue: boolean): Promise<boolean> {
const value = await getConfigValue(key, String(defaultValue));
return value === 'true';
const value = await getConfigValue(key, String(defaultValue))
return value === 'true'
}
/**
@@ -52,4 +61,4 @@ export const SEARCH_DEFAULTS = {
QUERY_EXPANSION_ENABLED: false,
QUERY_EXPANSION_MAX_SYNONYMS: 3,
DEBUG_MODE: false,
} as const;
} as const