Move parser out to on demand (maybe move to on-startup, or on schedule, later)

This commit is contained in:
2025-10-10 12:47:47 +01:00
parent 029aea7f0c
commit 7c827975ae
7 changed files with 215 additions and 360 deletions

View File

@@ -0,0 +1,20 @@
import { promises as fs } from 'fs';
import path from 'path';
import { Register } from '@/utils/parser';
import { parseNextReg } from '@/utils/parser';
let registers: Register[] = [];
/**
* Gets the registers from the in-memory cache, or loads them from the file if not already loaded.
* @returns A promise that resolves to an array of Register objects.
*/
export async function getRegisters(): Promise<Register[]> {
if (registers.length === 0) {
const filePath = path.join(process.cwd(), 'data', 'nextreg.txt');
const fileContent = await fs.readFile(filePath, 'utf8');
registers = await parseNextReg(fileContent);
}
return registers;
}