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) { if (arch != null && deviceType != null) {
return [undefined, arch, deviceType]; return [undefined, arch, deviceType];
} else { } else {
return Promise.join( return helpers
helpers.getApplication(application), .getAppWithArch(application)
helpers.getArchAndDeviceType(application), .then(app => [app, app.arch, app.device_type]);
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],
);
} }
}) })

View File

@ -296,20 +296,8 @@ Examples:
}); });
} }
}) })
.then(() => .then(() => helpers.getAppWithArch(appName))
Promise.join( .then(function(app) {
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]) {
return Promise.join( return Promise.join(
dockerUtils.getDocker(options), dockerUtils.getDocker(options),
dockerUtils.generateBuildOpts(options), dockerUtils.generateBuildOpts(options),
@ -319,8 +307,8 @@ Examples:
app, app,
appName, // may be prefixed by 'owner/', unlike app.app_name appName, // may be prefixed by 'owner/', unlike app.app_name
image, image,
shouldPerformBuild, shouldPerformBuild: !!options.build,
shouldUploadLogs, shouldUploadLogs: !options.nologupload,
buildEmulated: !!options.emulated, buildEmulated: !!options.emulated,
buildOpts, buildOpts,
convertEol: options.convertEol, convertEol: options.convertEol,

View File

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