From c3a305f807f728cc935771d4f8a675ddc024375f Mon Sep 17 00:00:00 2001 From: Jai Bhagat Date: Wed, 5 Jan 2022 12:43:51 -0500 Subject: [PATCH] fix: move node loading to jobs.job route and add auth logic --- ui/app/controllers/jobs/job/clients.js | 4 +--- ui/app/routes/jobs/job.js | 5 +++++ ui/app/routes/jobs/job/index.js | 8 +++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ui/app/controllers/jobs/job/clients.js b/ui/app/controllers/jobs/job/clients.js index a4b7f05df..a7735784c 100644 --- a/ui/app/controllers/jobs/job/clients.js +++ b/ui/app/controllers/jobs/job/clients.js @@ -67,9 +67,7 @@ export default class ClientsController extends Controller.extend( @computed('store') get allNodes() { - return this.store.peekAll('node').length - ? this.store.peekAll('node') - : this.store.findAll('node'); + return this.store.peekAll('node'); } @computed('allNodes', 'jobClientStatus.byNode') diff --git a/ui/app/routes/jobs/job.js b/ui/app/routes/jobs/job.js index 3a01c84ba..a39c16183 100644 --- a/ui/app/routes/jobs/job.js +++ b/ui/app/routes/jobs/job.js @@ -33,6 +33,11 @@ export default class JobRoute extends Route { relatedModelsQueries.push(job.get('recommendationSummaries')); } + // Optimizing future node look ups by preemptively loading everything + if (job.get('hasClientStatus') && this.can.can('read client')) { + relatedModelsQueries.push(this.store.findAll('node')); + } + return RSVP.all(relatedModelsQueries).then(() => job); }) .catch(notifyError(this)); diff --git a/ui/app/routes/jobs/job/index.js b/ui/app/routes/jobs/job/index.js index ba2e81d1c..f5b7d7b32 100644 --- a/ui/app/routes/jobs/job/index.js +++ b/ui/app/routes/jobs/job/index.js @@ -1,3 +1,4 @@ +import { inject as service } from '@ember/service'; import Route from '@ember/routing/route'; import { collect } from '@ember/object/computed'; import { @@ -9,9 +10,9 @@ import { import WithWatchers from 'nomad-ui/mixins/with-watchers'; export default class IndexRoute extends Route.extend(WithWatchers) { + @service can; + async model() { - // Optimizing future node look ups by preemptively loading everything - await this.store.findAll('node'); return this.modelFor('jobs.job'); } @@ -30,7 +31,8 @@ export default class IndexRoute extends Route.extend(WithWatchers) { list: model.get('hasChildren') && this.watchAllJobs.perform({ namespace: model.namespace.get('name') }), - nodes: model.get('hasClientStatus') && this.watchNodes.perform(), + nodes: + model.get('hasClientStatus') && this.can.can('read client') && this.watchNodes.perform(), }); }