Deduplicate balenaUrl fetching in events

Change-type: patch
This commit is contained in:
Pagan Gazzard 2020-02-29 21:14:01 +00:00
parent c8cade95da
commit 47e85da789

View File

@ -22,10 +22,9 @@ import * as Mixpanel from 'mixpanel';
import * as packageJSON from '../package.json';
import { getBalenaSdk } from './utils/lazy';
const getMixpanel = _.once<any>(() => {
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<any>(() => {
*/
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 => {