Skip to content
This repository has been archived by the owner on May 18, 2024. It is now read-only.

InsertCollction.getDependencies() can cause infinite function calls #64

Closed
samchon opened this issue Mar 21, 2022 · 0 comments
Closed
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@samchon
Copy link
Owner

samchon commented Mar 21, 2022

As below code is configuring key and value pair of the dependencies after the recursive function call of itself, the infinite function calls could be occured if two tables are dependent on each other. Therefore, move the dependencies.set(target, output); statement from line 171 to 156. By bring the statement in front of the recursive function call, any infinite function call must not be occured.

function getDependencies<T extends object>
(target: Creator<T>, connection?: orm.Connection): Set<Creator<object>>
{
if (!connection)
connection = findRepository(target).manager.connection;
let output: Set<Creator<object>> | undefined = dependencies.get(target);
if (output === undefined)
{
output = new Set();
for (const meta of connection.entityMetadatas)
{
const child: Creator<object> = meta.target as Creator<object>;
if (child === target)
continue;
for (const foreign of meta.foreignKeys)
if (foreign.referencedEntityMetadata.target === target)
{
output.add(child);
for (const grand of getDependencies(child, connection))
output.add(grand);
break;
}
}
dependencies.set(target, output);
}
return output;
}
const dependencies: WeakMap<Creator<object>, Set<Creator<object>>> = new WeakMap();

@samchon samchon added bug Something isn't working enhancement New feature or request labels Mar 21, 2022
@samchon samchon self-assigned this Mar 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant