Use dedicated permalink creators in search results with multiple rooms

Fixes https://github.com/vector-im/riot-web/issues/9376

This also would have happened in "All Rooms" searches.
This commit is contained in:
Travis Ralston 2019-04-08 16:23:00 -06:00
parent 054011f5f8
commit c49afe4d72

View file

@ -1161,6 +1161,10 @@ module.exports = React.createClass({
} }
}; };
// We cache the permalink creators to avoid creating a ton of them in popular searches
const permalinkCreators = {}; // [roomId] => creator
permalinkCreators[this.state.room.roomId] = this.state.permalinkCreator;
let lastRoomId; let lastRoomId;
for (let i = this.state.searchResults.results.length - 1; i >= 0; i--) { for (let i = this.state.searchResults.results.length - 1; i >= 0; i--) {
@ -1168,6 +1172,7 @@ module.exports = React.createClass({
const mxEv = result.context.getEvent(); const mxEv = result.context.getEvent();
const roomId = mxEv.getRoomId(); const roomId = mxEv.getRoomId();
const room = cli.getRoom(roomId);
if (!EventTile.haveTileForEvent(mxEv)) { if (!EventTile.haveTileForEvent(mxEv)) {
// XXX: can this ever happen? It will make the result count // XXX: can this ever happen? It will make the result count
@ -1177,7 +1182,6 @@ module.exports = React.createClass({
if (this.state.searchScope === 'All') { if (this.state.searchScope === 'All') {
if (roomId != lastRoomId) { if (roomId != lastRoomId) {
const room = cli.getRoom(roomId);
// XXX: if we've left the room, we might not know about // XXX: if we've left the room, we might not know about
// it. We should tell the js sdk to go and find out about // it. We should tell the js sdk to go and find out about
@ -1194,11 +1198,17 @@ module.exports = React.createClass({
const resultLink = "#/room/"+roomId+"/"+mxEv.getId(); const resultLink = "#/room/"+roomId+"/"+mxEv.getId();
let permalinkCreator = permalinkCreators[roomId];
if (!permalinkCreator) {
permalinkCreator = permalinkCreators[roomId] = new RoomPermalinkCreator(room);
permalinkCreator.stop(); // We're not interested in monitoring for updates here.
}
ret.push(<SearchResultTile key={mxEv.getId()} ret.push(<SearchResultTile key={mxEv.getId()}
searchResult={result} searchResult={result}
searchHighlights={this.state.searchHighlights} searchHighlights={this.state.searchHighlights}
resultLink={resultLink} resultLink={resultLink}
permalinkCreator={this.state.permalinkCreator} permalinkCreator={permalinkCreator}
onHeightChanged={onHeightChanged} />); onHeightChanged={onHeightChanged} />);
} }
return ret; return ret;