fix(providence): fix ast cache (prevent from endless expanding); expose amountOfCachedProjects

This commit is contained in:
Thijs Louisse 2025-03-20 09:15:47 +01:00 committed by Thijs Louisse
parent 9827228b83
commit e0d2a759b6
2 changed files with 5 additions and 4 deletions

View file

@ -2,4 +2,5 @@
'providence-analytics': minor 'providence-analytics': minor
--- ---
use globby again - use globby again
- fix ast cache (prevent from endless expanding); expose amountOfCachedProjects

View file

@ -146,12 +146,12 @@ export class QueryService {
} }
// In order to prevent running out of memory, there is a limit to the number of // In order to prevent running out of memory, there is a limit to the number of
// project ASTs in cache. For a session running multiple analyzers for reference // project ASTs in cache. For a session running multiple analyzers for reference
// and target projects, we need this number to be at least 2. if (astProjectsDataCache.size >= this.amountOfCachedProjects) {
if (astProjectsDataCache.size >= 2) { astProjectsDataCache.delete(astProjectsDataCache.keys().next().value);
astProjectsDataCache.delete(astProjectsDataCache.keys()[0]);
} }
astProjectsDataCache.set(pathAndRequiredAst, astData); astProjectsDataCache.set(pathAndRequiredAst, astData);
} }
} }
QueryService.cacheDisabled = false; QueryService.cacheDisabled = false;
QueryService.amountOfCachedProjects = 2;
QueryService.addAstToProjectsData = memoize(QueryService.addAstToProjectsData); QueryService.addAstToProjectsData = memoize(QueryService.addAstToProjectsData);