From 40b01af8f8f12f349835d3adb907eafb26643552 Mon Sep 17 00:00:00 2001 From: Thomas Belin Date: Wed, 26 Jun 2024 17:38:29 +0200 Subject: [PATCH] chore: initialize datadog as soon as possible (#17656) --- src/script/main/app.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/script/main/app.ts b/src/script/main/app.ts index a96db8eb402..2650428b057 100644 --- a/src/script/main/app.ts +++ b/src/script/main/app.ts @@ -372,6 +372,11 @@ export class App { onProgress(2.5); telemetry.timeStep(AppInitTimingsStep.RECEIVED_ACCESS_TOKEN); + const selfUser = await this.repository.user.getSelf([{position: 'App.initiateSelfUser', vendor: 'webapp'}]); + + await initializeDataDog(this.config, selfUser.qualifiedId); + onProgress(5, t('initReceivedSelfUser', selfUser.name())); + try { await this.core.init(clientType); } catch (error) { @@ -384,7 +389,7 @@ export class App { userRepository.addClientToUser(userId, newClient, true); }); - const selfUser = await this.initiateSelfUser(); + await this.initiateSelfUser(selfUser); const localClient = await this.core.getLocalClient(); if (!localClient) { @@ -403,8 +408,6 @@ export class App { }, }); - await initializeDataDog(this.config, selfUser.qualifiedId); - // Setup all event middleware const eventStorageMiddleware = new EventStorageMiddleware(this.service.event, selfUser); const serviceMiddleware = new ServiceMiddleware(conversationRepository, userRepository, selfUser); @@ -423,7 +426,6 @@ export class App { const federationEventProcessor = new FederationEventProcessor(eventRepository, serverTimeHandler, selfUser); eventRepository.setEventProcessors([federationEventProcessor]); - onProgress(5, t('initReceivedSelfUser', selfUser.name())); telemetry.timeStep(AppInitTimingsStep.RECEIVED_SELF_USER); const clientEntity = await this._initiateSelfUserClients(selfUser, clientRepository); callingRepository.initAvs(selfUser, clientEntity.id); @@ -612,20 +614,18 @@ export class App { * Initiate the self user by getting it from the backend. * @returns Resolves with the self user entity */ - private async initiateSelfUser() { - const userEntity = await this.repository.user.getSelf([{position: 'App.initiateSelfUser', vendor: 'webapp'}]); - - if (!userEntity.hasActivatedIdentity()) { - if (!userEntity.isTemporaryGuest()) { + private async initiateSelfUser(selfUser: User) { + if (!selfUser.hasActivatedIdentity()) { + if (!selfUser.isTemporaryGuest()) { throw new Error('User does not have an activated identity'); } } container.resolve(StorageService).init(this.core.storage); - this.repository.client.init(userEntity); - await this.repository.properties.init(userEntity); + this.repository.client.init(selfUser); + await this.repository.properties.init(selfUser); - return userEntity; + return selfUser; } /**