From d7933352872504e344edb1b1ba3dfe1c3b0d69fd Mon Sep 17 00:00:00 2001 From: Thodoris Greasidis Date: Tue, 7 Sep 2021 02:09:39 +0300 Subject: [PATCH] preload: Replace my_application query with the SDKs application.getAll() Change-type: patch Signed-off-by: Thodoris Greasidis --- lib/commands/preload.ts | 61 ++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/lib/commands/preload.ts b/lib/commands/preload.ts index cf1ec164..945e4908 100644 --- a/lib/commands/preload.ts +++ b/lib/commands/preload.ts @@ -331,7 +331,6 @@ Can be repeated to add multiple certificates.\ readonly applicationExpandOptions: PineExpand = { owns__release: { $select: ['id', 'commit', 'end_timestamp', 'composition'], - $orderby: [{ end_timestamp: 'desc' }, { id: 'desc' }], $expand: { contains__image: { $select: ['image'], @@ -345,6 +344,7 @@ Can be repeated to add multiple certificates.\ $filter: { status: 'success', }, + $orderby: [{ end_timestamp: 'desc' }, { id: 'desc' }], }, should_be_running__release: { $select: 'commit', @@ -378,44 +378,37 @@ Can be repeated to add multiple certificates.\ const balena = getBalenaSdk(); const deviceTypes = await this.getDeviceTypesWithSameArch(deviceTypeSlug); - // TODO: remove the explicit types once https://github.com/balena-io/balena-sdk/pull/889 gets merged - return balena.pine.get< - Application, - Array< - ApplicationWithDeviceType & { - should_be_running__release: [Release?]; - } - > - >({ - resource: 'my_application', - options: { - $filter: { - is_for__device_type: { - $any: { - $alias: 'dt', - $expr: { - dt: { - slug: { $in: deviceTypes }, - }, - }, - }, - }, - owns__release: { - $any: { - $alias: 'r', - $expr: { - r: { - status: 'success', - }, + return (await balena.models.application.getAll({ + $select: ['id', 'app_name', 'should_track_latest_release'], + $expand: this.applicationExpandOptions, + $filter: { + is_for__device_type: { + $any: { + $alias: 'dt', + $expr: { + dt: { + slug: { $in: deviceTypes }, + }, + }, + }, + }, + owns__release: { + $any: { + $alias: 'r', + $expr: { + r: { + status: 'success', }, }, }, }, - $expand: this.applicationExpandOptions, - $select: ['id', 'app_name', 'should_track_latest_release'], - $orderby: 'app_name asc', }, - }); + $orderby: 'app_name asc', + })) as Array< + ApplicationWithDeviceType & { + should_be_running__release: [Release?]; + } + >; } async selectApplication(deviceTypeSlug: string) {