Prevent unnecessary calc in home roomlist
authorAjay Bura <ajbura@gmail.com>
Mon, 14 Mar 2022 12:04:34 +0000 (17:34 +0530)
committerAjay Bura <ajbura@gmail.com>
Mon, 14 Mar 2022 12:04:34 +0000 (17:34 +0530)
Signed-off-by: Ajay Bura <ajbura@gmail.com>
src/app/organisms/navigation/Home.jsx
src/client/state/RoomList.js

index 95bf88e9ce3eec83d1bce4870d5967e6061fbba3..c52ead499d143f5c3b320a0a80d900aa0d996654 100644 (file)
@@ -15,9 +15,7 @@ const drawerPostie = new Postie();
 function Home({ spaceId }) {
   const mx = initMatrix.matrixClient;
   const { roomList, notifications, accountData } = initMatrix;
-  const {
-    spaces, rooms, directs, roomIdToParents,
-  } = roomList;
+  const { spaces, rooms, directs } = roomList;
   useCategorizedSpaces();
   const isCategorized = accountData.categorizedSpaces.has(spaceId);
 
@@ -26,14 +24,14 @@ function Home({ spaceId }) {
   let roomIds = [];
   let directIds = [];
 
-  const spaceChildIds = roomList.getSpaceChildren(spaceId);
-  if (spaceChildIds) {
+  if (spaceId) {
+    const spaceChildIds = roomList.getSpaceChildren(spaceId);
     spaceIds = spaceChildIds.filter((roomId) => spaces.has(roomId));
     roomIds = spaceChildIds.filter((roomId) => rooms.has(roomId));
     directIds = spaceChildIds.filter((roomId) => directs.has(roomId));
   } else {
-    spaceIds = [...spaces].filter((roomId) => !roomIdToParents.has(roomId));
-    roomIds = [...rooms].filter((roomId) => !roomIdToParents.has(roomId));
+    spaceIds = roomList.getOrphanSpaces();
+    roomIds = roomList.getOrphanRooms();
   }
 
   spaceIds.sort(AtoZ);
index ec3c060a16fabb73990157f139f3d54e075e5352..f1e0d6d00c08bcf7e7057245bb6f19678a76fa1d 100644 (file)
@@ -36,6 +36,14 @@ class RoomList extends EventEmitter {
     return !this.roomIdToParents.has(roomId);
   }
 
+  getOrphanSpaces() {
+    return [...this.spaces].filter((roomId) => !this.roomIdToParents.has(roomId));
+  }
+
+  getOrphanRooms() {
+    return [...this.rooms].filter((roomId) => !this.roomIdToParents.has(roomId));
+  }
+
   getOrphans() {
     const rooms = [...this.spaces].concat([...this.rooms]);
     return rooms.filter((roomId) => !this.roomIdToParents.has(roomId));