Fix getParentSpaces can cause call stack overflow

Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
Ajay Bura 2022-03-13 15:36:15 +05:30
parent d6b880d110
commit 7cf5df80ce

View file

@ -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) {