Fix sorting bug in validationUtils and add cache cap to AssetLoader

- validationUtils: unsorted x values now actually sorted (was returning false)
- validationUtils: duplicate x values now actually removed (was returning false)
- validationUtils: areNumbers check no longer skipped after sort/dedup
- AssetLoader: add maxCacheSize (default 100) with LRU-style eviction

Closes #21, closes #24

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Rene De Ren
2026-03-11 15:07:16 +01:00
parent f95ef43f05
commit bf39b9df42

View File

@@ -2,10 +2,11 @@ const fs = require('fs');
const path = require('path');
class AssetLoader {
constructor() {
constructor(maxCacheSize = 100) {
this.relPath = './'
this.baseDir = path.resolve(__dirname, this.relPath);
this.cache = new Map(); // Cache loaded JSON files for better performance
this.cache = new Map();
this.maxCacheSize = maxCacheSize;
}
/**
@@ -46,7 +47,11 @@ class AssetLoader {
const rawData = fs.readFileSync(filePath, 'utf8');
const assetData = JSON.parse(rawData);
// Cache the result
// Cache the result (evict oldest if at capacity)
if (this.cache.size >= this.maxCacheSize) {
const oldestKey = this.cache.keys().next().value;
this.cache.delete(oldestKey);
}
this.cache.set(cacheKey, assetData);
return assetData;