From 039d1728c3f80552e4bd3643dbda23dedb9e951f Mon Sep 17 00:00:00 2001 From: Otavio Jacobi Date: Wed, 27 Nov 2024 13:16:57 -0300 Subject: [PATCH] Remove usage of service_install resource on state get v3 Change-type: patch --- .../device-state/routes/state-get-v3.ts | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/features/device-state/routes/state-get-v3.ts b/src/features/device-state/routes/state-get-v3.ts index 9a25dcc74..3befc6204 100644 --- a/src/features/device-state/routes/state-get-v3.ts +++ b/src/features/device-state/routes/state-get-v3.ts @@ -12,7 +12,6 @@ import { getStateDelayingEmpty, getStateEventAdditionalFields, readTransaction, - serviceInstallFromImage, varListInsert, } from '../state-get-utils.js'; import { sbvrUtils } from '@balena/pinejs'; @@ -137,6 +136,14 @@ export function buildAppFromRelease( } } + const dsevsById = + device != null + ? _.groupBy( + device.device_service_environment_variable, + ({ service }) => service.__id, + ) + : {}; + for (const ipr of release.release_image) { const image = ipr.image[0]; const svc = image.is_a_build_of__service[0]; @@ -156,9 +163,9 @@ export function buildAppFromRelease( if (device != null) { varListInsert(device.device_environment_variable, environment); - const si = serviceInstallFromImage(device, image); - if (si != null) { - varListInsert(si.device_service_environment_variable, environment); + const dsevs = dsevsById[svc.id]; + if (dsevs != null) { + varListInsert(dsevs, environment); } } @@ -274,13 +281,8 @@ const deviceExpand = { }, // `should_be_running__release` will automatically defer to the app release as necessary should_be_running__release: releaseExpand, - service_install: { - $select: ['id', 'service'], - $expand: { - device_service_environment_variable: { - $select: ['name', 'value'], - }, - }, + device_service_environment_variable: { + $select: ['name', 'value', 'service'], }, belongs_to__application: { $select: appSelect,