Omit private rooms from Rooms.global.chatRooms

Rooms.global.chatRooms is a cached list of chat rooms, useful since
Rooms.rooms on Main has thousands of rooms on average, while less
than 100 of them are chat rooms.

A scan through the code reveals that private rooms are never used
(except for .isPrivate === 'voice') when we need .chatRooms, so
we can omit them to make the cache even smaller/faster.

This is a fairly minor optimization (we have fewer private rooms
than public rooms, total) and private rooms are omitted lazily
(only upon server restart) because we have to check .isPrivate
for the === 'voice' case anyway.
This commit is contained in:
Guangcong Luo 2015-03-22 00:51:25 -04:00
parent d89a77ac87
commit 7925516d13
2 changed files with 6 additions and 1 deletions

View File

@ -247,6 +247,9 @@ var commands = exports.commands = {
delete room.chatRoomData.isPrivate;
Rooms.global.writeChatRoomData();
}
if (Rooms.global.chatRooms.indexOf(room) < 0) {
Rooms.global.chatRooms.push(room);
}
} else {
room.isPrivate = setting;
this.addModCommand("" + user.name + " made this room " + (setting === true ? 'secret' : setting) + ".");

View File

@ -197,6 +197,8 @@ var GlobalRoom = (function () {
}];
}
// cached list of chat rooms for the room list
// usually does not contain private rooms, but no guarantees
this.chatRooms = [];
this.autojoin = []; // rooms that users autojoin upon connecting
@ -214,7 +216,7 @@ var GlobalRoom = (function () {
aliases[room.aliases[a]] = room;
}
}
this.chatRooms.push(room);
if (!room.isPrivate || room.isPrivate === 'voice') this.chatRooms.push(room);
if (room.autojoin) this.autojoin.push(id);
if (room.staffAutojoin) this.staffAutojoin.push(id);
}