Cache room alias to room ID mapping in memory

This adds very basic cache (literally just a `Map` for now) to store room alias
to room ID mappings. The improves the perceived performance of Riot when
switching rooms via browser navigation (back / forward), as we no longer try to
resolve the room alias every time.

The cache is only in memory, so reloading manually or as part of the clear cache
process will start afresh.

Fixes https://github.com/vector-im/riot-web/issues/10020
This commit is contained in:
J. Ryan Stinnett 2019-11-12 11:43:18 +00:00
parent df1d5055c0
commit d72dedb0ce
3 changed files with 66 additions and 7 deletions

View file

@ -60,6 +60,7 @@ import AutoDiscoveryUtils from "../../utils/AutoDiscoveryUtils";
import DMRoomMap from '../../utils/DMRoomMap';
import { countRoomsWithNotif } from '../../RoomNotifs';
import { setTheme } from "../../theme";
import { storeRoomAliasInCache } from '../../RoomAliasCache';
// Disable warnings for now: we use deprecated bluebird functions
// and need to migrate, but they spam the console with warnings.
@ -866,7 +867,12 @@ export default createReactClass({
const room = MatrixClientPeg.get().getRoom(roomInfo.room_id);
if (room) {
const theAlias = Rooms.getDisplayAliasForRoom(room);
if (theAlias) presentedId = theAlias;
if (theAlias) {
presentedId = theAlias;
// Store display alias of the presented room in cache to speed future
// navigation.
storeRoomAliasInCache(theAlias, room.roomId);
}
// Store this as the ID of the last room accessed. This is so that we can
// persist which room is being stored across refreshes and browser quits.