Skip to content

Commit 6ff1c30

Browse files
committed
Fix spurious fill requests when switching networks
Ignore responses for old servers too, don't trigger a backfill request when we re-render before refresh. Also a few more comments.
1 parent 85ea45a commit 6ff1c30

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

‎src/components/structures/RoomDirectory.js‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,16 @@ module.exports = React.createClass({
9898
if (!MatrixClientPeg.get()) return q();
9999

100100
const my_filter_string = this.filterString;
101+
const my_server = this.state.roomServer;
101102
const opts = {limit: 20};
102-
if (this.state.roomServer != MatrixClientPeg.getHomeServerName()) {
103-
opts.server = this.state.roomServer;
103+
if (my_server != MatrixClientPeg.getHomeServerName()) {
104+
opts.server = my_server;
104105
}
105106
if (this.nextBatch) opts.since = this.nextBatch;
106107
if (this.filterString) opts.filter = { generic_search_term: my_filter_string } ;
107108
return MatrixClientPeg.get().publicRooms(opts).then((data) => {
108-
if (my_filter_string != this.filterString) {
109-
// if the filter has changed since this request was sent,
109+
if (my_filter_string != this.filterString || my_server != this.state.roomServer) {
110+
// if the filter or server has changed since this request was sent,
110111
// throw away the result (don't even clear the busy flag
111112
// since we must still have a request in flight)
112113
return;
@@ -120,7 +121,7 @@ module.exports = React.createClass({
120121
});
121122
return Boolean(data.next_batch);
122123
}, (err) => {
123-
if (my_filter_string != this.filterString) {
124+
if (my_filter_string != this.filterString || my_server != this.state.roomServer) {
124125
// as above: we don't care about errors for old
125126
// requests either
126127
return;
@@ -195,10 +196,22 @@ module.exports = React.createClass({
195196
},
196197

197198
onOptionChange: function(server, network) {
199+
// clear next batch so we don't try to load more rooms
200+
this.nextBatch = null;
198201
this.setState({
202+
// Clear the public rooms out here otherwise we needlessly
203+
// spend time filtering lots of rooms when we're about to
204+
// to clear the list anyway.
205+
publicRooms: [],
199206
roomServer: server,
200207
filterByNetwork: network,
201208
}, this.refreshRoomList);
209+
// We also refresh the room list each time even though this
210+
// filtering is client-side. It hopefully won't be client side
211+
// for very long, and we may have fetched a thousand rooms to
212+
// find the five gitter ones, at which point we do not want
213+
// to render all those rooms when switching back to 'all networks'.
214+
// Easiest to just blow away the state & re-fetch.
202215
},
203216

204217
onFillRequest: function(backwards) {

0 commit comments

Comments
 (0)