Fix getParentSpaces can cause call stack overflow
Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
parent
d6b880d110
commit
7cf5df80ce
1 changed files with 15 additions and 7 deletions
|
@ -92,13 +92,21 @@ class RoomList extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
getParentSpaces(roomId) {
|
getParentSpaces(roomId) {
|
||||||
let parentIds = this.roomIdToParents.get(roomId);
|
const allParents = new Set();
|
||||||
if (parentIds) {
|
const processed = new Set();
|
||||||
[...parentIds].forEach((parentId) => {
|
const addAllParentIds = (rId) => {
|
||||||
parentIds = new Set([...parentIds, ...this.getParentSpaces(parentId)]);
|
if (processed.has(rId)) return;
|
||||||
});
|
processed.add(rId);
|
||||||
}
|
|
||||||
return parentIds || new Set();
|
const parents = this.roomIdToParents.get(rId);
|
||||||
|
if (parents === undefined) return;
|
||||||
|
|
||||||
|
parents.forEach((id) => allParents.add(id));
|
||||||
|
parents.forEach((id) => addAllParentIds(id));
|
||||||
|
};
|
||||||
|
addAllParentIds(roomId);
|
||||||
|
processed.clear();
|
||||||
|
return allParents;
|
||||||
}
|
}
|
||||||
|
|
||||||
addToSpaces(roomId) {
|
addToSpaces(roomId) {
|
||||||
|
|
Loading…
Reference in a new issue