Wait a bit before sending filter requests

avoid hammering the server with requests for each keystroke
pull/2241/head
David Baker 2016-09-16 18:53:18 +01:00
parent 6d332256b5
commit 2fdec51a5b
1 changed files with 13 additions and 1 deletions

View File

@ -66,6 +66,7 @@ module.exports = React.createClass({
}
this.nextBatch = null;
this.filterString = null;
this.filterTimeout = null;
// dis.dispatch({
// action: 'ui_opacity',
@ -209,7 +210,18 @@ module.exports = React.createClass({
this.showRoomAlias(alias);
} else {
this.filterString = alias || null;
this.refreshRoomList();
// don't send the request for a little bit,
// no point hammering the server with a
// request for every keystroke, let the
// user finish typing.
if (this.filterTimeout) {
clearTimeout(this.filterTimeout);
}
this.filterTimeout = setTimeout(() => {
this.filterTimeout = null;
this.refreshRoomList();
}, 300);
}
},