From 12eac04484e3c0a347b6f31783ed7973991046fa Mon Sep 17 00:00:00 2001 From: Felipe Lalanne <1822826+pipex@users.noreply.github.com> Date: Wed, 14 Jun 2023 17:08:29 -0400 Subject: [PATCH] Fix /v2/applications/state endpoint It was returning stale information, particularly the download progress of the target release images never got updated. Change-type: patch Closes: #2174 --- src/device-api/v2.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/device-api/v2.ts b/src/device-api/v2.ts index a7840d3d..23824262 100644 --- a/src/device-api/v2.ts +++ b/src/device-api/v2.ts @@ -156,8 +156,8 @@ router.post( router.get( '/v2/applications/state', async (req: AuthorizedRequest, res: Response, next: NextFunction) => { - // It's kinda hacky to access the services and db via the application manager - // maybe refactor this code + // It's very hacky to access the services and db via the application manager + // refactor this code to use applicationManager.getState() instead. Bluebird.join( serviceManager.getState(), images.getState(), @@ -183,6 +183,7 @@ router.get( } = {}; const appNameById: { [id: number]: string } = {}; + const commits: string[] = []; // only access scoped apps apps @@ -198,11 +199,17 @@ router.get( }; appNameById[appId] = app.name; + commits.push(app.commit); }); // only access scoped images imgs - .filter((img) => req.auth.isScoped({ apps: [img.appId] })) + .filter( + (img) => + req.auth.isScoped({ apps: [img.appId] }) && + // Ensure we are using the apps for the target release + commits.includes(img.commit), + ) .forEach((img) => { const appName = appNameById[img.appId]; if (appName == null) { @@ -214,8 +221,10 @@ router.get( return; } - const svc = _.find(services, (service: Service) => { - return service.imageId === img.imageId; + const svc = _.find(services, (s: Service) => { + return ( + s.serviceName === img.serviceName && s.commit === img.commit + ); }); let status: string | undefined;