ssh,tunnel: Fetch the fleet & devices in one request

Change-type: patch
This commit is contained in:
Thodoris Greasidis 2023-05-23 19:14:27 +03:00
parent 81f4aae7d2
commit 861d4f33b7

View File

@ -317,6 +317,12 @@ export async function getOnlineTargetDeviceUuid(
const { getApplication } = await import('./sdk');
return await getApplication(sdk, fleetOrDevice, {
$select: ['id', 'slug'],
$expand: {
owns__device: {
$select: ['device_name', 'uuid'],
$filter: { is_online: true },
},
},
});
} catch (err) {
const { BalenaApplicationNotFound } = await import('balena-errors');
@ -329,10 +335,7 @@ export async function getOnlineTargetDeviceUuid(
})();
// App found, load its devices
const devices = await sdk.models.device.getAllByApplication(application.id, {
$select: ['device_name', 'uuid'],
$filter: { is_online: true },
});
const devices = application.owns__device;
// Throw if no devices online
if (_.isEmpty(devices)) {