Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Avoid hitting the SettingsStore thousands of times when generating ro…
Browse files Browse the repository at this point in the history
…om lists

Should fix element-hq/element-web#7646 to some degree
  • Loading branch information
turt2live committed Nov 1, 2018
1 parent 57b9989 commit 5558b7a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/stores/RoomListStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,16 @@ class RoomListStore extends Store {
}
});

// Note: we check the settings up here instead of in the forEach or
// in the _recentsComparator to avoid hitting the SettingsStore a few
// thousand times.
const pinUnread = SettingsStore.getValue("pinUnreadRooms");
const pinMentioned = SettingsStore.getValue("pinMentionedRooms");
Object.keys(lists).forEach((listKey) => {
let comparator;
switch (RoomListStore._listOrders[listKey]) {
case "recent":
comparator = this._recentsComparator;
comparator = (roomA, roomB) => this._recentsComparator(roomA, roomB, pinUnread, pinMentioned);
break;
case "manual":
default:
Expand Down Expand Up @@ -262,10 +267,7 @@ class RoomListStore extends Store {
}
}

_recentsComparator(roomA, roomB) {
const pinUnread = SettingsStore.getValue("pinUnreadRooms");
const pinMentioned = SettingsStore.getValue("pinMentionedRooms");

_recentsComparator(roomA, roomB, pinUnread, pinMentioned) {
// We try and set the ordering to be Mentioned > Unread > Recent
// assuming the user has the right settings, of course

Expand Down

0 comments on commit 5558b7a

Please sign in to comment.