From adedc6e3eea8c6a6c83627edd27612564e4a2ef2 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Thu, 4 Feb 2021 12:03:57 -0500 Subject: [PATCH] refactor: Remove EmberArray use in /target/hosts to simplify --- .../scope/projects/targets/target/hosts.js | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js b/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js index 8b23f7025..fda131f12 100644 --- a/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js +++ b/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js @@ -1,6 +1,5 @@ import Route from '@ember/routing/route'; import { all } from 'rsvp'; -import { A } from '@ember/array'; export default class ScopesScopeProjectsTargetsTargetHostsRoute extends Route { // =methods @@ -11,25 +10,26 @@ export default class ScopesScopeProjectsTargetsTargetHostsRoute extends Route { */ async model() { const { host_sets } = this.modelFor('scopes.scope.projects.targets.target'); - const hostSetsPromises = await all( + // Load all host-sets + const hostSets = await all( host_sets.map(({ host_set_id }) => this.store.findRecord('host-set', host_set_id) ) ); - // Extract host ids from all host set - const hostIds = A(); - hostSetsPromises.map(({ host_ids }) => - host_ids.forEach(({ value }) => hostIds.push(value) ) - ); - - // Fetch all hosts - const hostPromises = await all( - hostIds.uniq().map((hostId) => - this.store.findRecord('host', hostId) - ) + // Extract host ids from all host sets + const hostIds = hostSets.map(({host_ids}) => + host_ids.content.map((hostId) => + hostId.value + ) ) - return all(hostPromises); + // Load unique hosts + const uniqueHostIds = new Set(hostIds.flat()); + return all( + [...uniqueHostIds].map((hostId) => + this.store.findRecord('host', hostId) + ) + ); } }