Skip to content

Commit

Permalink
[backend] Prevent cache loop by removing recursive algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-julien committed Jan 8, 2025
1 parent 7f5e7d0 commit 318f6f9
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions opencti-platform/opencti-graphql/src/database/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,19 @@ const getEntitiesFromCache = async <T extends BasicStoreIdentifier | StixObject>
throw UnsupportedError('Cache configuration type not supported', { type });
}
if (!fromCache.values) {
if (!fromCache.inProgress) {
fromCache.inProgress = true;
// If cache already in progress build, just wait for completion
if (fromCache.inProgress) {
while (fromCache.inProgress) {
await wait(100);
}
return fromCache.values ?? (type === ENTITY_TYPE_RESOLVED_FILTERS ? new Map() : []);
}
// If not in progress, re fetch the data
fromCache.inProgress = true;
try {
fromCache.values = await fromCache.fn();
} finally {
fromCache.inProgress = false;
} else {
await wait(100);
return getEntitiesFromCache(context, user, type);
}
}
return fromCache.values ?? (type === ENTITY_TYPE_RESOLVED_FILTERS ? new Map() : []);
Expand Down

0 comments on commit 318f6f9

Please sign in to comment.