Merge pull request #2339 from matrix-org/travis/speed-up-room-list

Speed up room unread checks by not hitting the SettingsStore so often
This commit is contained in:
Travis Ralston 2018-12-08 12:16:30 -07:00 committed by GitHub
commit 780315817c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -38,18 +38,20 @@ function memberEventDiff(ev) {
}
export default function shouldHideEvent(ev) {
// Wrap getValue() for readability
// Wrap getValue() for readability. Calling the SettingsStore can be
// fairly resource heavy, so the checks below should avoid hitting it
// where possible.
const isEnabled = (name) => SettingsStore.getValue(name, ev.getRoomId());
// Hide redacted events
if (isEnabled('hideRedactions') && ev.isRedacted()) return true;
if (ev.isRedacted() && isEnabled('hideRedactions')) return true;
const eventDiff = memberEventDiff(ev);
if (eventDiff.isMemberEvent) {
if (isEnabled('hideJoinLeaves') && (eventDiff.isJoin || eventDiff.isPart)) return true;
if (isEnabled('hideAvatarChanges') && eventDiff.isAvatarChange) return true;
if (isEnabled('hideDisplaynameChanges') && eventDiff.isDisplaynameChange) return true;
if ((eventDiff.isJoin || eventDiff.isPart) && isEnabled('hideJoinLeaves')) return true;
if (eventDiff.isAvatarChange && isEnabled('hideAvatarChanges')) return true;
if (eventDiff.isDisplaynameChange && isEnabled('hideDisplaynameChanges')) return true;
}
return false;