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) {
|
||||
let parentIds = this.roomIdToParents.get(roomId);
|
||||
if (parentIds) {
|
||||
[...parentIds].forEach((parentId) => {
|
||||
parentIds = new Set([...parentIds, ...this.getParentSpaces(parentId)]);
|
||||
});
|
||||
}
|
||||
return parentIds || new Set();
|
||||
const allParents = new Set();
|
||||
const processed = new Set();
|
||||
const addAllParentIds = (rId) => {
|
||||
if (processed.has(rId)) return;
|
||||
processed.add(rId);
|
||||
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue