From f6e4e75193f35acc3bda5f59ed55acecfb134ff8 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Wed, 24 Jul 2024 12:48:07 +0200 Subject: [PATCH 1/7] enable collecting performance data in firebase --- src/libs/actions/Timing.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Timing.ts b/src/libs/actions/Timing.ts index 28ffdd92ffba9..6244ab2a609bc 100644 --- a/src/libs/actions/Timing.ts +++ b/src/libs/actions/Timing.ts @@ -19,7 +19,7 @@ let timestampData: Record = {}; * @param eventName * @param shouldUseFirebase - adds an additional trace in Firebase */ -function start(eventName: string, shouldUseFirebase = false) { +function start(eventName: string, shouldUseFirebase = true) { timestampData[eventName] = {startTime: Date.now(), shouldUseFirebase}; if (!shouldUseFirebase) { From 49ea16bee185136bb64a7041bf81557543a8458b Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Wed, 24 Jul 2024 15:05:22 +0200 Subject: [PATCH 2/7] attach account attributes to trace --- src/libs/Firebase/index.native.ts | 10 ++++++++++ src/libs/PersonalDetailsUtils.ts | 5 +++++ src/libs/ReportConnection.ts | 6 +++++- src/libs/SessionUtils.ts | 10 +++++++++- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/libs/Firebase/index.native.ts b/src/libs/Firebase/index.native.ts index 75884bed59b6f..7e0569a3dfdd3 100644 --- a/src/libs/Firebase/index.native.ts +++ b/src/libs/Firebase/index.native.ts @@ -2,6 +2,9 @@ import crashlytics from '@react-native-firebase/crashlytics'; import perf from '@react-native-firebase/perf'; import * as Environment from '@libs/Environment/Environment'; +import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; +import * as ReportConnection from '@libs/ReportConnection'; +import * as SessionUtils from '@libs/SessionUtils'; import type {Log, StartTrace, StopTrace, TraceMap} from './types'; const traceMap: TraceMap = {}; @@ -12,6 +15,10 @@ const startTrace: StartTrace = (customEventName) => { return; } + const countAllReports = ReportConnection.countAllReports(); + const countPersonalDetails = PersonalDetailsUtils.countPersonalDetails(); + const session = SessionUtils.getSession(); + if (traceMap[customEventName]) { return; } @@ -19,6 +26,9 @@ const startTrace: StartTrace = (customEventName) => { perf() .startTrace(customEventName) .then((trace) => { + trace.putAttribute('accountID', session?.accountID?.toString() ?? 'N/A'); + trace.putAttribute('reports', countAllReports.toString()); + trace.putAttribute('personalDetails', countPersonalDetails.toString()); traceMap[customEventName] = { trace, start, diff --git a/src/libs/PersonalDetailsUtils.ts b/src/libs/PersonalDetailsUtils.ts index 9beb3d382696b..ce08512368769 100644 --- a/src/libs/PersonalDetailsUtils.ts +++ b/src/libs/PersonalDetailsUtils.ts @@ -310,6 +310,10 @@ function isPersonalDetailsEmpty() { return !personalDetails.length; } +function countPersonalDetails() { + return personalDetails.length; +} + export { isPersonalDetailsEmpty, getDisplayNameOrDefault, @@ -325,4 +329,5 @@ export { createDisplayName, extractFirstAndLastNameFromAvailableDetails, getNewAccountIDsAndLogins, + countPersonalDetails, }; diff --git a/src/libs/ReportConnection.ts b/src/libs/ReportConnection.ts index 86e73229e84b8..ecb9f7a5bc5ba 100644 --- a/src/libs/ReportConnection.ts +++ b/src/libs/ReportConnection.ts @@ -44,4 +44,8 @@ function getAllReportsNameMap() { return reportIDToNameMap; } -export {getAllReports, getAllReportsNameMap}; +function countAllReports() { + return allReports ? Object.keys(allReports).length : 0; +} + +export {getAllReports, getAllReportsNameMap, countAllReports}; diff --git a/src/libs/SessionUtils.ts b/src/libs/SessionUtils.ts index e8854e158b487..88c4f01e17d11 100644 --- a/src/libs/SessionUtils.ts +++ b/src/libs/SessionUtils.ts @@ -1,5 +1,7 @@ import Onyx from 'react-native-onyx'; +import type {OnyxEntry} from 'react-native-onyx'; import ONYXKEYS from '@src/ONYXKEYS'; +import type * as OnyxTypes from '@src/types/onyx'; /** * Determine if the transitioning user is logging in as a new user. @@ -26,12 +28,14 @@ function isLoggingInAsNewUser(transitionURL?: string, sessionEmail?: string): bo } let loggedInDuringSession: boolean | undefined; +let currentSession: OnyxEntry; // To tell if the user logged in during this session we will check the value of session.authToken once when the app's JS inits. When the user logs out // we can reset this flag so that it can be updated again. Onyx.connect({ key: ONYXKEYS.SESSION, callback: (session) => { + currentSession = session; if (loggedInDuringSession) { return; } @@ -53,4 +57,8 @@ function didUserLogInDuringSession() { return !!loggedInDuringSession; } -export {isLoggingInAsNewUser, didUserLogInDuringSession, resetDidUserLogInDuringSession}; +function getSession() { + return currentSession; +} + +export {isLoggingInAsNewUser, didUserLogInDuringSession, resetDidUserLogInDuringSession, getSession}; From 14eb38b00cdbf3eb6c0d7a9a9881a52e2338ce33 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Wed, 24 Jul 2024 16:43:28 +0200 Subject: [PATCH 3/7] fix tests --- tests/unit/OptionsListUtilsTest.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/unit/OptionsListUtilsTest.ts b/tests/unit/OptionsListUtilsTest.ts index 79f19649f3373..df2e3ca49836e 100644 --- a/tests/unit/OptionsListUtilsTest.ts +++ b/tests/unit/OptionsListUtilsTest.ts @@ -13,6 +13,13 @@ import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; type PersonalDetailsList = Record; +jest.mock('@src/libs/actions/Timing', () => { + return { + start: jest.fn(), + end: jest.fn(), + }; +}); + describe('OptionsListUtils', () => { // Given a set of reports with both single participants and multiple participants some pinned and some not const REPORTS: OnyxCollection = { From 04a99966b576c1c017def0b34f6332723409a842 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Thu, 25 Jul 2024 11:46:58 +0200 Subject: [PATCH 4/7] mock timing on perf tests --- tests/perf-test/OptionsListUtils.perf-test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/perf-test/OptionsListUtils.perf-test.ts b/tests/perf-test/OptionsListUtils.perf-test.ts index 16522297a4162..5e15d43c45b28 100644 --- a/tests/perf-test/OptionsListUtils.perf-test.ts +++ b/tests/perf-test/OptionsListUtils.perf-test.ts @@ -73,6 +73,13 @@ jest.mock('@react-navigation/native', () => { }; }); +jest.mock('@src/libs/actions/Timing', () => { + return { + start: jest.fn(), + end: jest.fn(), + }; +}); + const options = OptionsListUtils.createOptionList(personalDetails, reports); /* GetOption is the private function and is never called directly, we are testing the functions which call getOption with different params */ From aa78d9e5eb9ab86a60c789d439104d74b03b3b00 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Thu, 25 Jul 2024 12:35:53 +0200 Subject: [PATCH 5/7] Revert "mock timing on perf tests" This reverts commit 04a99966b576c1c017def0b34f6332723409a842. --- tests/perf-test/OptionsListUtils.perf-test.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/perf-test/OptionsListUtils.perf-test.ts b/tests/perf-test/OptionsListUtils.perf-test.ts index 5e15d43c45b28..16522297a4162 100644 --- a/tests/perf-test/OptionsListUtils.perf-test.ts +++ b/tests/perf-test/OptionsListUtils.perf-test.ts @@ -73,13 +73,6 @@ jest.mock('@react-navigation/native', () => { }; }); -jest.mock('@src/libs/actions/Timing', () => { - return { - start: jest.fn(), - end: jest.fn(), - }; -}); - const options = OptionsListUtils.createOptionList(personalDetails, reports); /* GetOption is the private function and is never called directly, we are testing the functions which call getOption with different params */ From 85137b506a128f181dd77d6606f105546d424405 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Thu, 25 Jul 2024 12:37:32 +0200 Subject: [PATCH 6/7] Revert "fix tests" This reverts commit 14eb38b00cdbf3eb6c0d7a9a9881a52e2338ce33. --- tests/unit/OptionsListUtilsTest.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/unit/OptionsListUtilsTest.ts b/tests/unit/OptionsListUtilsTest.ts index df2e3ca49836e..79f19649f3373 100644 --- a/tests/unit/OptionsListUtilsTest.ts +++ b/tests/unit/OptionsListUtilsTest.ts @@ -13,13 +13,6 @@ import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; type PersonalDetailsList = Record; -jest.mock('@src/libs/actions/Timing', () => { - return { - start: jest.fn(), - end: jest.fn(), - }; -}); - describe('OptionsListUtils', () => { // Given a set of reports with both single participants and multiple participants some pinned and some not const REPORTS: OnyxCollection = { From c331083ecae1553adcfe9617093231e92667f1e6 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Thu, 25 Jul 2024 12:37:52 +0200 Subject: [PATCH 7/7] Revert "attach account attributes to trace" This reverts commit 49ea16bee185136bb64a7041bf81557543a8458b. --- src/libs/Firebase/index.native.ts | 10 ---------- src/libs/PersonalDetailsUtils.ts | 5 ----- src/libs/ReportConnection.ts | 6 +----- src/libs/SessionUtils.ts | 10 +--------- 4 files changed, 2 insertions(+), 29 deletions(-) diff --git a/src/libs/Firebase/index.native.ts b/src/libs/Firebase/index.native.ts index 7e0569a3dfdd3..75884bed59b6f 100644 --- a/src/libs/Firebase/index.native.ts +++ b/src/libs/Firebase/index.native.ts @@ -2,9 +2,6 @@ import crashlytics from '@react-native-firebase/crashlytics'; import perf from '@react-native-firebase/perf'; import * as Environment from '@libs/Environment/Environment'; -import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; -import * as ReportConnection from '@libs/ReportConnection'; -import * as SessionUtils from '@libs/SessionUtils'; import type {Log, StartTrace, StopTrace, TraceMap} from './types'; const traceMap: TraceMap = {}; @@ -15,10 +12,6 @@ const startTrace: StartTrace = (customEventName) => { return; } - const countAllReports = ReportConnection.countAllReports(); - const countPersonalDetails = PersonalDetailsUtils.countPersonalDetails(); - const session = SessionUtils.getSession(); - if (traceMap[customEventName]) { return; } @@ -26,9 +19,6 @@ const startTrace: StartTrace = (customEventName) => { perf() .startTrace(customEventName) .then((trace) => { - trace.putAttribute('accountID', session?.accountID?.toString() ?? 'N/A'); - trace.putAttribute('reports', countAllReports.toString()); - trace.putAttribute('personalDetails', countPersonalDetails.toString()); traceMap[customEventName] = { trace, start, diff --git a/src/libs/PersonalDetailsUtils.ts b/src/libs/PersonalDetailsUtils.ts index ce08512368769..9beb3d382696b 100644 --- a/src/libs/PersonalDetailsUtils.ts +++ b/src/libs/PersonalDetailsUtils.ts @@ -310,10 +310,6 @@ function isPersonalDetailsEmpty() { return !personalDetails.length; } -function countPersonalDetails() { - return personalDetails.length; -} - export { isPersonalDetailsEmpty, getDisplayNameOrDefault, @@ -329,5 +325,4 @@ export { createDisplayName, extractFirstAndLastNameFromAvailableDetails, getNewAccountIDsAndLogins, - countPersonalDetails, }; diff --git a/src/libs/ReportConnection.ts b/src/libs/ReportConnection.ts index ecb9f7a5bc5ba..86e73229e84b8 100644 --- a/src/libs/ReportConnection.ts +++ b/src/libs/ReportConnection.ts @@ -44,8 +44,4 @@ function getAllReportsNameMap() { return reportIDToNameMap; } -function countAllReports() { - return allReports ? Object.keys(allReports).length : 0; -} - -export {getAllReports, getAllReportsNameMap, countAllReports}; +export {getAllReports, getAllReportsNameMap}; diff --git a/src/libs/SessionUtils.ts b/src/libs/SessionUtils.ts index 88c4f01e17d11..e8854e158b487 100644 --- a/src/libs/SessionUtils.ts +++ b/src/libs/SessionUtils.ts @@ -1,7 +1,5 @@ import Onyx from 'react-native-onyx'; -import type {OnyxEntry} from 'react-native-onyx'; import ONYXKEYS from '@src/ONYXKEYS'; -import type * as OnyxTypes from '@src/types/onyx'; /** * Determine if the transitioning user is logging in as a new user. @@ -28,14 +26,12 @@ function isLoggingInAsNewUser(transitionURL?: string, sessionEmail?: string): bo } let loggedInDuringSession: boolean | undefined; -let currentSession: OnyxEntry; // To tell if the user logged in during this session we will check the value of session.authToken once when the app's JS inits. When the user logs out // we can reset this flag so that it can be updated again. Onyx.connect({ key: ONYXKEYS.SESSION, callback: (session) => { - currentSession = session; if (loggedInDuringSession) { return; } @@ -57,8 +53,4 @@ function didUserLogInDuringSession() { return !!loggedInDuringSession; } -function getSession() { - return currentSession; -} - -export {isLoggingInAsNewUser, didUserLogInDuringSession, resetDidUserLogInDuringSession, getSession}; +export {isLoggingInAsNewUser, didUserLogInDuringSession, resetDidUserLogInDuringSession};