From 852d6a3be5a4bb2d9c3c6ee42fd4fafd64e08dc8 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 22 Aug 2018 14:34:02 +0100 Subject: [PATCH 1/2] Fix CPU spin on joining large room checkIfAlone() filters the whole member list, which is fine until we do it once for every membership event, then we have an n^2 problem. Move it into the rate limited function. Fixes https://github.com/vector-im/riot-web/issues/7163 --- src/components/structures/RoomView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 855090873f..1ecd7dad2e 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -701,7 +701,6 @@ module.exports = React.createClass({ } this._updateRoomMembers(); - this._checkIfAlone(this.state.room); }, onRoomMemberMembership: function(ev, member, oldMembership) { @@ -717,6 +716,7 @@ module.exports = React.createClass({ // refresh the conf call notification state this._updateConfCallNotification(); this._updateDMState(); + this._checkIfAlone(this.state.room); }, 500), _checkIfAlone: function(room) { From a5f98b6a29675f1acc09f655e63230a6d366f499 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 22 Aug 2018 17:05:36 +0100 Subject: [PATCH 2/2] Make the is-alone check use efficient methods --- src/components/structures/RoomView.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 1ecd7dad2e..dd8fba3929 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -729,8 +729,8 @@ module.exports = React.createClass({ return; } - const joinedMembers = room.currentState.getMembers().filter((m) => m.membership === "join" || m.membership === "invite"); - this.setState({isAlone: joinedMembers.length === 1}); + const joinedOrInvitedMemberCount = room.getJoinedMemberCount() + room.getInvitedMemberCount(); + this.setState({isAlone: joinedOrInvitedMemberCount === 1}); }, _updateConfCallNotification: function() {