Merge pull request #2585 from matrix-org/bwindels/throttlecustomtags

Fix: throttle custom tags updating in LLP
This commit is contained in:
Bruno Windels 2019-02-07 16:15:57 +00:00 committed by GitHub
commit b50bfa1eda
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,6 +17,7 @@ import dis from '../dispatcher';
import * as RoomNotifs from '../RoomNotifs';
import RoomListStore from './RoomListStore';
import EventEmitter from 'events';
import { throttle } from "lodash";
const STANDARD_TAGS_REGEX = /^(m\.(favourite|lowpriority|server_notice)|im\.vector\.fake\.(invite|recent|direct|archived))$/;
@ -49,7 +50,14 @@ class CustomRoomTagStore extends EventEmitter {
super();
// Initialise state
this._state = {tags: {}};
// as RoomListStore gets updated by every timeline event
// throttle this to only run every 500ms
this._getUpdatedTags = throttle(
this._getUpdatedTags, 500, {
leading: true,
trailing: true,
},
);
this._roomListStoreToken = RoomListStore.addListener(() => {
this._setState({tags: this._getUpdatedTags()});
});