From 9c821511b117c6128134936af115d368c1d743ce Mon Sep 17 00:00:00 2001 From: Thodoris Greasidis Date: Tue, 7 Sep 2021 07:53:02 +0000 Subject: [PATCH] device move: Rely on the device type model to get the compatible apps Connects-to: #2318 Change-type: patch See: https://www.flowdock.com/app/rulemotion/i-cli/threads/s6x4Z_LoH8IG4PC_YeXMC0TP6v- Signed-off-by: Thodoris Greasidis --- lib/commands/device/move.ts | 55 ++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/lib/commands/device/move.ts b/lib/commands/device/move.ts index 8d2018d6..bbad496c 100644 --- a/lib/commands/device/move.ts +++ b/lib/commands/device/move.ts @@ -145,28 +145,45 @@ export default class DeviceMoveCmd extends Command { balena: BalenaSDK, devices: ExtendedDevice[], ) { + const { getExpandedProp } = await import('../../utils/pine'); const [deviceDeviceTypes, deviceTypes] = await Promise.all([ - Promise.all( - devices.map((device) => - balena.models.device.getManifestBySlug( - device.is_of__device_type[0].slug, - ), - ), - ), - balena.models.config.getDeviceTypes(), + balena.models.deviceType.getAll({ + $select: 'slug', + $expand: { + is_of__cpu_architecture: { + $select: 'slug', + }, + }, + $filter: { + slug: { + // deduplicate the device type slugs + $in: Array.from( + new Set( + devices.map((device) => device.is_of__device_type[0].slug), + ), + ), + }, + }, + }), + balena.models.deviceType.getAllSupported({ + $select: 'slug', + $expand: { + is_of__cpu_architecture: { + $select: 'slug', + }, + }, + }), ]); - const compatibleDeviceTypes = deviceTypes.filter((dt) => - deviceDeviceTypes.every( - (deviceDeviceType) => - balena.models.os.isArchitectureCompatibleWith( - deviceDeviceType.arch, - dt.arch, - ) && - !!dt.isDependent === !!deviceDeviceType.isDependent && - dt.state !== 'DISCONTINUED', - ), - ); + const compatibleDeviceTypes = deviceTypes.filter((dt) => { + const dtArch = getExpandedProp(dt.is_of__cpu_architecture, 'slug')!; + return deviceDeviceTypes.every((deviceDeviceType) => + balena.models.os.isArchitectureCompatibleWith( + getExpandedProp(deviceDeviceType.is_of__cpu_architecture, 'slug')!, + dtArch, + ), + ); + }); const patterns = await import('../../utils/patterns'); try {