From 5c5307c6650b7fb51b031c7a9f05b49748a6b096 Mon Sep 17 00:00:00 2001 From: lukebarnard Date: Wed, 3 Jan 2018 17:12:31 +0000 Subject: [PATCH] Improve performance of tag panel selection (when tags are selected) Deselecting all tags is now slightly less performant than selecting a tag but mostly due to the number of RoomTiles being rendered. Swapping between different tags (a supposed common use-case) feels much more spritely! --- src/components/views/rooms/RoomList.js | 31 +++++++++++++++++--------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/components/views/rooms/RoomList.js b/src/components/views/rooms/RoomList.js index f14ba5529d..9fc3a5f231 100644 --- a/src/components/views/rooms/RoomList.js +++ b/src/components/views/rooms/RoomList.js @@ -311,11 +311,6 @@ module.exports = React.createClass({ }); }, - isRoomInSelectedTags: function(room) { - // No selected tags = every room is visible in the list - return this.state.selectedTags.length === 0 || this._visibleRooms.includes(room.roomId); - }, - refreshRoomList: function() { // TODO: ideally we'd calculate this once at start, and then maintain // any changes to it incrementally, updating the appropriate sublists @@ -344,7 +339,26 @@ module.exports = React.createClass({ lists["im.vector.fake.archived"] = []; const dmRoomMap = DMRoomMap.shared(); - MatrixClientPeg.get().getRooms().forEach((room) => { + + // If there are any tags selected, constrain the rooms listed to the + // visible rooms as determined by this._visibleRooms. Here, we + // de-duplicate and filter out rooms that the client doesn't know + // about (hence the Set and the null-guard on `room`). + let rooms = []; + if (this.state.selectedTags.length > 0) { + const roomSet = new Set(); + this._visibleRooms.forEach((roomId) => { + const room = MatrixClientPeg.get().getRoom(roomId); + if (room) { + roomSet.add(room); + } + }); + rooms = Array.from(roomSet); + } else { + rooms = MatrixClientPeg.get().getRooms(); + } + + rooms.forEach((room, index) => { const me = room.getMember(MatrixClientPeg.get().credentials.userId); if (!me) return; @@ -362,11 +376,6 @@ module.exports = React.createClass({ // Used to split rooms via tags const tagNames = Object.keys(room.tags); - // Apply TagPanel filtering, derived from FilterStore - if (!this.isRoomInSelectedTags(room)) { - return; - } - if (tagNames.length) { for (let i = 0; i < tagNames.length; i++) { const tagName = tagNames[i];