Skip to content

Commit 2fdec51

Browse files
committed
Wait a bit before sending filter requests
avoid hammering the server with requests for each keystroke
1 parent 6d33225 commit 2fdec51

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/components/structures/RoomDirectory.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ module.exports = React.createClass({
6666
}
6767
this.nextBatch = null;
6868
this.filterString = null;
69+
this.filterTimeout = null;
6970

7071
// dis.dispatch({
7172
// action: 'ui_opacity',
@@ -209,7 +210,18 @@ module.exports = React.createClass({
209210
this.showRoomAlias(alias);
210211
} else {
211212
this.filterString = alias || null;
212-
this.refreshRoomList();
213+
214+
// don't send the request for a little bit,
215+
// no point hammering the server with a
216+
// request for every keystroke, let the
217+
// user finish typing.
218+
if (this.filterTimeout) {
219+
clearTimeout(this.filterTimeout);
220+
}
221+
this.filterTimeout = setTimeout(() => {
222+
this.filterTimeout = null;
223+
this.refreshRoomList();
224+
}, 300);
213225
}
214226
},
215227

0 commit comments

Comments
 (0)