Merge pull request #1799 from balena-io/avoid-unnecessary-api-calls

Avoid unnecessary api calls in `balena build` and `balena deploy`
This commit is contained in:
Page- 2020-05-01 17:29:44 +01:00 committed by GitHub
commit b84cdd6230
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 36 deletions

View File

@ -182,22 +182,9 @@ Examples:
if (arch != null && deviceType != null) {
return [undefined, arch, deviceType];
} else {
return Promise.join(
helpers.getApplication(application),
helpers.getArchAndDeviceType(application),
function(
app,
{ arch: resolvedArch, device_type: resolvedDeviceType },
) {
// @ts-ignore extending the app object
app.arch = resolvedArch;
app.device_type = resolvedDeviceType;
return app;
},
).then(app =>
// @ts-ignore using the extended prop
[app, app.arch, app.device_type],
);
return helpers
.getAppWithArch(application)
.then(app => [app, app.arch, app.device_type]);
}
})

View File

@ -296,20 +296,8 @@ Examples:
});
}
})
.then(() =>
Promise.join(
helpers.getApplication(appName),
helpers.getArchAndDeviceType(appName),
function(app, { arch, device_type }) {
// @ts-ignore extending the app object
app.arch = arch;
app.device_type = device_type;
return app;
},
).then(app => [app, !!options.build, !options.nologupload]),
)
.then(function([app, shouldPerformBuild, shouldUploadLogs]) {
.then(() => helpers.getAppWithArch(appName))
.then(function(app) {
return Promise.join(
dockerUtils.getDocker(options),
dockerUtils.generateBuildOpts(options),
@ -319,8 +307,8 @@ Examples:
app,
appName, // may be prefixed by 'owner/', unlike app.app_name
image,
shouldPerformBuild,
shouldUploadLogs,
shouldPerformBuild: !!options.build,
shouldUploadLogs: !options.nologupload,
buildEmulated: !!options.emulated,
buildOpts,
convertEol: options.convertEol,

View File

@ -143,9 +143,9 @@ export async function osProgressHandler(step: InitializeEmitter) {
});
}
export function getArchAndDeviceType(
export function getAppWithArch(
applicationName: string,
): Bluebird<{ arch: string; device_type: string }> {
): Bluebird<BalenaSdk.Application & { arch: string }> {
return Bluebird.join(
getApplication(applicationName),
getBalenaSdk().models.config.getDeviceTypes(),
@ -158,12 +158,12 @@ export function getArchAndDeviceType(
throw new Error('Could not read application information!');
}
return { device_type: app.device_type, arch: config.arch };
return { ...app, arch: config.arch };
},
);
}
export function getApplication(applicationName: string) {
function getApplication(applicationName: string) {
// Check for an app of the form `user/application`, and send
// that off to a special handler (before importing any modules)
const match = applicationName.split('/');