only generate type data once

This commit is contained in:
outfoxxed 2024-10-24 19:40:53 -07:00
parent 8fb1408bb4
commit e0a2fb0256
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
6 changed files with 21 additions and 11 deletions

View file

@ -30,7 +30,7 @@ async function readSubdir(subdir: string): Promise<dirData[]> {
return data;
}
export async function generateTypeData(): Promise<RouteData[]> {
async function generateTypeData(): Promise<RouteData[]> {
const mainDir = import.meta.env.SECRET_MODULES_PATH;
if (!mainDir || mainDir == "") {
@ -56,3 +56,13 @@ export async function generateTypeData(): Promise<RouteData[]> {
}
return routes;
}
let globalTypeData: Promise<RouteData[]>;
export function getTypeData(): Promise<RouteData[]> {
if (!globalTypeData) {
globalTypeData = generateTypeData();
}
return globalTypeData;
}