Skip to content

Commit

Permalink
var-update-trigger: Skip querying for affected devices on image env v…
Browse files Browse the repository at this point in the history
…ar POSTs of non-successful releases

Change-type: patch
  • Loading branch information
thgreasi committed Oct 17, 2024
1 parent 58849cb commit abd32e8
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/features/vars-schema/hooks/vars-update-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,39 @@ addEnvHooks('device_service_environment_variable', async (args) => {

addEnvHooks('image_environment_variable', async (args) => {
if (args.req.body.release_image != null) {
// This is a optimization that allows skipping the following
// device->image_install->...->release_image query in most real world
// cases, since when user permissions are used it creates a complex query
// with high planning time. The idea is that image env vars are created
// while the release is still 'running', in which case we don't expect
// any device to possibly be running that release.
const isPartOfSuccessfulRelease =
(
await args.api.get({
resource: 'release',
options: {
$top: 1,
$select: 'id',
$filter: {
status: 'success',
release_image: {
$any: {
$alias: 'ri',
$expr: {
ri: {
id: args.req.body.release_image,
},
},
},
},
},
},
})
).length > 0;
if (!isPartOfSuccessfulRelease) {
return;
}

return {
image_install: {
$any: {
Expand All @@ -328,6 +361,7 @@ addEnvHooks('image_environment_variable', async (args) => {
$alias: 'i',
$expr: {
i: {
status: 'success',
release_image: {
$any: {
$alias: 'ri',
Expand Down Expand Up @@ -360,6 +394,7 @@ addEnvHooks('image_environment_variable', async (args) => {
$alias: 'i',
$expr: {
i: {
status: 'success',
release_image: {
$any: {
$alias: 'ri',
Expand Down

0 comments on commit abd32e8

Please sign in to comment.