diff --git a/src/lib/chat/matrix-client.ts b/src/lib/chat/matrix-client.ts index 3b58e791c..accded263 100644 --- a/src/lib/chat/matrix-client.ts +++ b/src/lib/chat/matrix-client.ts @@ -187,12 +187,17 @@ export class MatrixClient implements IChatClient { } async getConversations() { + featureFlags.enableTimerLogs && console.time('xxxgetConversations'); + await this.waitForConnection(); const rooms = await this.getRoomsUserIsIn(); const failedToJoin = []; for (const room of rooms) { + featureFlags.enableTimerLogs && console.time('xxxdecryptAllEvents'); await room.decryptAllEvents(); + featureFlags.enableTimerLogs && console.timeEnd('xxxdecryptAllEvents'); + await room.loadMembersIfNeeded(); const membership = room.getMyMembership(); @@ -208,7 +213,13 @@ export class MatrixClient implements IChatClient { const filteredRooms = rooms.filter((r) => !failedToJoin.includes(r.roomId)); await this.lowerMinimumInviteAndKickLevels(filteredRooms); - return await Promise.all(filteredRooms.map((r) => this.mapConversation(r))); + + featureFlags.enableTimerLogs && console.time('xxxmapConversationresult'); + const result = await Promise.all(filteredRooms.map((r) => this.mapConversation(r))); + featureFlags.enableTimerLogs && console.timeEnd('xxxmapConversationresult'); + + featureFlags.enableTimerLogs && console.timeEnd('xxxgetConversations'); + return result; } async getSecureBackup() { @@ -1020,6 +1031,8 @@ export class MatrixClient implements IChatClient { } private async initializeClient(userId: string, ssoToken: string) { + featureFlags.enableTimerLogs && console.time('xxxinitializeClient'); + if (!this.matrix) { const opts: any = { baseUrl: config.matrix.homeServerUrl, @@ -1038,8 +1051,11 @@ export class MatrixClient implements IChatClient { await this.matrix.startClient(); + featureFlags.enableTimerLogs && console.time('xxxWaitForSync'); await this.waitForSync(); + featureFlags.enableTimerLogs && console.timeEnd('xxxWaitForSync'); + featureFlags.enableTimerLogs && console.timeEnd('xxxinitializeClient'); return opts.userId; } } @@ -1154,18 +1170,31 @@ export class MatrixClient implements IChatClient { } private mapConversation = async (room: Room): Promise> => { + featureFlags.enableTimerLogs && console.time(`xxxmapConversation${room.roomId}`); + const otherMembers = this.getOtherMembersFromRoom(room).map((userId) => this.mapUser(userId)); const memberHistory = this.getMemberHistoryFromRoom(room).map((userId) => this.mapUser(userId)); const name = this.getRoomName(room); const avatarUrl = this.getRoomAvatar(room); const createdAt = this.getRoomCreatedAt(room); + + featureFlags.enableTimerLogs && console.time(`xxxgetAllMessagesFromRoom${room.roomId}`); const messages = await this.getAllMessagesFromRoom(room); + featureFlags.enableTimerLogs && console.timeEnd(`xxxgetAllMessagesFromRoom${room.roomId}`); + const unreadCount = room.getUnreadNotificationCount(NotificationCountType.Total); + + featureFlags.enableTimerLogs && console.time(`xxxisRoomFavorited${room.roomId}`); const isFavorite = await this.isRoomFavorited(room.roomId); + featureFlags.enableTimerLogs && console.timeEnd(`xxxisRoomFavorited${room.roomId}`); + + featureFlags.enableTimerLogs && console.time(`xxxisRoomMuted${room.roomId}`); const isMuted = await this.isRoomMuted(room.roomId); + featureFlags.enableTimerLogs && console.timeEnd(`xxxisRoomMuted${room.roomId}`); + const [admins, mods] = this.getRoomAdminsAndMods(room); - return { + const result = { id: room.roomId, name, icon: avatarUrl, @@ -1184,6 +1213,9 @@ export class MatrixClient implements IChatClient { isFavorite, isMuted, }; + + featureFlags.enableTimerLogs && console.timeEnd(`xxxmapConversation${room.roomId}`); + return result; }; private mapUser(matrixId: string): UserModel { diff --git a/src/lib/feature-flags.ts b/src/lib/feature-flags.ts index 9a4c9a474..93f836012 100644 --- a/src/lib/feature-flags.ts +++ b/src/lib/feature-flags.ts @@ -97,6 +97,14 @@ export class FeatureFlags { set enableUserSettings(value: boolean) { this._setBoolean('enableUserSettings', value); } + + get enableTimerLogs() { + return this._getBoolean('enableTimerLogs', false); + } + + set enableTimerLogs(value: boolean) { + this._setBoolean('enableTimerLogs', value); + } } export const featureFlags = new FeatureFlags(); diff --git a/src/store/channels-list/saga.ts b/src/store/channels-list/saga.ts index 4e917dc9e..f3b6dfa84 100644 --- a/src/store/channels-list/saga.ts +++ b/src/store/channels-list/saga.ts @@ -24,6 +24,7 @@ import { uniqNormalizedList } from '../utils'; import { channelListStatus, rawConversationsList } from './selectors'; import { setIsConversationsLoaded } from '../chat'; import { getUserReadReceiptPreference } from '../user-profile/saga'; +import { featureFlags } from '../../lib/feature-flags'; export function* mapToZeroUsers(channels: any[]) { let allMatrixIds = []; @@ -56,6 +57,8 @@ export function* fetchRoomAvatar(roomId) { } export function* fetchConversations() { + featureFlags.enableTimerLogs && console.time('xxxfetchConversations'); + yield put(setStatus(AsyncListStatus.Fetching)); const chatClient = yield call(chat.get); const conversations = yield call([ @@ -63,7 +66,11 @@ export function* fetchConversations() { chatClient.getConversations, ]); + featureFlags.enableTimerLogs && console.time('xxxmapToZeroUsers'); yield call(mapToZeroUsers, conversations); + featureFlags.enableTimerLogs && console.timeEnd('xxxmapToZeroUsers'); + + // Potentially move this to when we load app yield call(getUserReadReceiptPreference); const existingConversationList = yield select(denormalizeConversations); @@ -89,6 +96,8 @@ export function* fetchConversations() { const channel = yield call(getConversationsBus); yield put(channel, { type: ConversationEvents.ConversationsLoaded }); + + featureFlags.enableTimerLogs && console.timeEnd('xxxfetchConversations'); } export function userSelector(state, userIds) {