Skip to content

Commit

Permalink
Remove usage of service_install resource on state get v2
Browse files Browse the repository at this point in the history
Change-type: patch
  • Loading branch information
otaviojacobi committed Nov 24, 2024
1 parent 6f9c341 commit a70256a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/features/device-state/routes/state-get-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,13 @@ function buildAppFromRelease(
// extract the per-image information
const image = ipr.image[0];

const si = device.service_install.find(
({ service }) => service.__id === image.is_a_build_of__service[0].id,
);
const svc = image.is_a_build_of__service[0];
const environment: Dictionary<string> = {};
varListInsert(ipr.image_environment_variable, environment);
varListInsert(application.application_environment_variable, environment);
varListInsert(svc.service_environment_variable, environment);
varListInsert(device.device_environment_variable, environment);
if (si != null) {
varListInsert(si.device_service_environment_variable, environment);
}
varListInsert(svc.device_service_environment_variable, environment);

const labels: Dictionary<string> = {};
for (const { label_name, value } of [
Expand Down Expand Up @@ -188,6 +183,21 @@ const stateQuery = _.once(() =>
is_a_build_of__service: {
$select: ['id', 'service_name'],
$expand: {
device_service_environment_variable: {
$select: ['name', 'value'],
$filter: {
device: {
$any: {
$alias: 'd',
$expr: {
d: {
uuid: { '@': 'uuid' },
},
},
},
},
},
},
service_environment_variable: {
$select: ['name', 'value'],
},
Expand All @@ -208,14 +218,6 @@ const stateQuery = _.once(() =>
},
},
},
service_install: {
$select: ['id', 'service'],
$expand: {
device_service_environment_variable: {
$select: ['name', 'value'],
},
},
},
belongs_to__application: {
$select: ['id', 'app_name'],
$expand: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,12 @@
"service": "app1_service1",
"name": "name_si",
"value": "value_si"
},
"si2_svc": {
"user": "admin",
"device": "device2",
"service": "app1_service1",
"name": "name_si_2",
"value": "value_si_2"
}
}
7 changes: 7 additions & 0 deletions test/fixtures/03-device-state/devices.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,12 @@
"belongs_to__user": "admin",
"uuid": "c47e4dec05f76ee37c4b8e805c35c1eee54335803b3a40458928f8afce618c",
"is_pinned_on__release": "release1"
},
"device2": {
"belongs_to__application": "app1",
"device_type": "raspberry-pi",
"belongs_to__user": "admin",
"uuid": "b47e4dec05f76ee37c4b8e805c35c1eee54335803b3a40458928f8afce618c",
"is_pinned_on__release": "release1"
}
}

0 comments on commit a70256a

Please sign in to comment.