From 47e85da78958826e76e091ea45ee81428555ddd7 Mon Sep 17 00:00:00 2001 From: Pagan Gazzard Date: Sat, 29 Feb 2020 21:14:01 +0000 Subject: [PATCH] Deduplicate `balenaUrl` fetching in events Change-type: patch --- lib/events.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/events.ts b/lib/events.ts index 5438de8b..36f68583 100644 --- a/lib/events.ts +++ b/lib/events.ts @@ -22,10 +22,9 @@ import * as Mixpanel from 'mixpanel'; import * as packageJSON from '../package.json'; import { getBalenaSdk } from './utils/lazy'; -const getMixpanel = _.once(() => { - const settings = require('balena-settings-client'); +const getMixpanel = _.once((balenaUrl: string) => { return Mixpanel.init('balena-main', { - host: `api.${settings.get('balenaUrl')}`, + host: `api.${balenaUrl}`, path: '/mixpanel', protocol: 'https', }); @@ -47,10 +46,11 @@ const getMixpanel = _.once(() => { */ export function trackCommand(commandSignature: string) { const balena = getBalenaSdk(); + const balenaUrlPromise = balena.settings.get('balenaUrl'); return Bluebird.props({ - balenaUrl: balena.settings.get('balenaUrl'), + balenaUrl: balenaUrlPromise, username: balena.auth.whoami().catchReturn(undefined), - mixpanel: getMixpanel(), + mixpanel: balenaUrlPromise.then(getMixpanel), }) .then(({ username, balenaUrl, mixpanel }) => { Sentry.configureScope(scope => {