From 82734e8383d0ac341c3637942951b3db4ed1fa3d Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Thu, 22 Jan 2026 15:50:46 +0100 Subject: [PATCH] Refactor source directory handling in modelsProxyService.js - Introduced a cached source directory variable to optimize the retrieval of model paths. - Updated comments for clarity on the source directory logic and its impact on cache validation. --- backend/services/modelsProxyService.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/services/modelsProxyService.js b/backend/services/modelsProxyService.js index 6a99175..78daeea 100644 --- a/backend/services/modelsProxyService.js +++ b/backend/services/modelsProxyService.js @@ -17,9 +17,15 @@ const PUBLIC_MODELS = path.join(PROJECT_ROOT, 'frontend', 'public', MODELS_REL); const CACHE_DIR = path.join(BACKEND_DIR, 'data', 'model-cache'); const CLI_PATH = path.join(BACKEND_DIR, 'node_modules', '.bin', 'gltf-transform'); -/** Production: frontend/dist; Local: frontend/public. Ermittelt bei Bedarf. */ +/** Einmal ermitteltes Quellverzeichnis (frontend/dist oder frontend/public). */ +let _sourceDir = null; + +/** Production: frontend/dist; Local: frontend/public. Einmal pro Prozess festgelegt, damit + * isCacheValid() stets gegen dieselbe Quelle prüft (kein Wechsel zwischen dist/public). */ function getSourceDir() { - return fs.existsSync(DIST_MODELS) ? DIST_MODELS : PUBLIC_MODELS; + if (_sourceDir !== null) return _sourceDir; + _sourceDir = fs.existsSync(DIST_MODELS) ? DIST_MODELS : PUBLIC_MODELS; + return _sourceDir; } /** Erlaubte Dateinamen (nur [a-z0-9_.-]+.glb) */