From 7f10d12c24868291284370b64f1c6ca4439fba38 Mon Sep 17 00:00:00 2001 From: Thomas Belin Date: Tue, 16 Apr 2024 10:31:31 +0200 Subject: [PATCH] perf: Improve polling the team feature config [WPB-8734] (#17274) --- src/script/team/TeamRepository.ts | 7 +++++-- src/script/util/DebugUtil.ts | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/script/team/TeamRepository.ts b/src/script/team/TeamRepository.ts index 0695438844f..ecced58edda 100644 --- a/src/script/team/TeamRepository.ts +++ b/src/script/team/TeamRepository.ts @@ -160,14 +160,17 @@ export class TeamRepository extends TypedEventEmitter { } private readonly scheduleTeamRefresh = (): void => { - window.setInterval(async () => { + const updateTeam = async () => { try { await this.getTeam(); await this.updateFeatureConfig(); } catch (error) { this.logger.error(error); } - }, TIME_IN_MILLIS.SECOND * 30); + }; + // We want to poll the latest team data every time the app is focused and every day + window.addEventListener('focus', updateTeam); + window.setInterval(updateTeam, TIME_IN_MILLIS.DAY); }; private async getInitialTeamMembers(teamId: string): Promise { diff --git a/src/script/util/DebugUtil.ts b/src/script/util/DebugUtil.ts index e23590e25aa..5bb1a2c68b3 100644 --- a/src/script/util/DebugUtil.ts +++ b/src/script/util/DebugUtil.ts @@ -280,6 +280,11 @@ export class DebugUtil { }); } + // Used by QA to trigger a focus event on the app (in order to trigger the update of the team feature-config) + simulateAppToForeground() { + window.dispatchEvent(new FocusEvent('focus')); + } + setE2EICertificateTtl(ttl: number) { E2EIHandler.getInstance().certificateTtl = ttl; }