Skip to content

Commit

Permalink
feat: add timer logs and behind feature flag (#2085)
Browse files Browse the repository at this point in the history
  • Loading branch information
domw30 committed Jul 9, 2024
1 parent 603eb1d commit dadefd9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/lib/chat/matrix-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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() {
Expand Down Expand Up @@ -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,
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -1154,18 +1170,31 @@ export class MatrixClient implements IChatClient {
}

private mapConversation = async (room: Room): Promise<Partial<Channel>> => {
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,
Expand All @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions src/lib/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 9 additions & 0 deletions src/store/channels-list/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -56,14 +57,20 @@ 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([
chatClient,
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);
Expand All @@ -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) {
Expand Down

0 comments on commit dadefd9

Please sign in to comment.