From afe8a694f6367b72698ee7fb375f5995278849ba Mon Sep 17 00:00:00 2001 From: Kirin Patel Date: Thu, 15 Aug 2019 17:00:28 -0700 Subject: [PATCH] Reduce API usage by utilizing reference name in reference resource API (#1824) * Regenerated run api for frontend * Added support for reference name to resource reference API in frontend * Revert "Regenerated run api for frontend" * Addressed PR comments * Removed extra if statement by setting default value of parameter * Removed the whole comment * Addressed PR feedback * Addressed PR feedback * Simplified logic after offline discussion --- frontend/src/lib/RunUtils.ts | 22 +++++++++++++++------- frontend/src/pages/RunList.tsx | 26 ++++++++++++++------------ 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/frontend/src/lib/RunUtils.ts b/frontend/src/lib/RunUtils.ts index 69548dbbe98..eb696df8378 100644 --- a/frontend/src/lib/RunUtils.ts +++ b/frontend/src/lib/RunUtils.ts @@ -29,6 +29,11 @@ export interface MetricMetadata { name: string; } +export interface ExperimentInfo { + displayName?: string; + id: string; +} + function getParametersFromRun(run: ApiRunDetail): ApiParameter[] { return getParametersFromRuntime(run.pipeline_runtime); } @@ -59,16 +64,18 @@ function getWorkflowManifest(run?: ApiRun | ApiJob): string | null { return (run && run.pipeline_spec && run.pipeline_spec.workflow_manifest) || null; } +function getFirstExperimentReference(run?: ApiRun | ApiJob): ApiResourceReference | null { + return getAllExperimentReferences(run)[0] || null; +} + function getFirstExperimentReferenceId(run?: ApiRun | ApiJob): string | null { - if (run) { - const reference = getAllExperimentReferences(run)[0]; - return reference && reference.key && reference.key.id || null; - } - return null; + const reference = getFirstExperimentReference(run); + return reference && reference.key && reference.key.id || null; } -function getFirstExperimentReference(run?: ApiRun | ApiJob): ApiResourceReference | null { - return run && getAllExperimentReferences(run)[0] || null; +function getFirstExperimentReferenceName(run?: ApiRun | ApiJob): string | null { + const reference = getFirstExperimentReference(run); + return reference && reference.name || null; } function getAllExperimentReferences(run?: ApiRun | ApiJob): ApiResourceReference[] { @@ -133,6 +140,7 @@ export default { getAllExperimentReferences, getFirstExperimentReference, getFirstExperimentReferenceId, + getFirstExperimentReferenceName, getParametersFromRun, getParametersFromRuntime, getPipelineId, diff --git a/frontend/src/pages/RunList.tsx b/frontend/src/pages/RunList.tsx index e033cb81560..4f1bff25e3e 100644 --- a/frontend/src/pages/RunList.tsx +++ b/frontend/src/pages/RunList.tsx @@ -17,7 +17,7 @@ import * as React from 'react'; import CustomTable, { Column, Row, CustomRendererProps } from '../components/CustomTable'; import Metric from '../components/Metric'; -import RunUtils, { MetricMetadata } from '../../src/lib/RunUtils'; +import RunUtils, { MetricMetadata, ExperimentInfo } from '../../src/lib/RunUtils'; import { ApiRun, ApiResourceType, ApiRunMetric, RunStorageState, ApiRunDetail } from '../../src/apis/run'; import { Apis, RunSortKeys, ListRequest } from '../lib/Apis'; import { Link, RouteComponentProps } from 'react-router-dom'; @@ -29,11 +29,6 @@ import { commonCss, color } from '../Css'; import { formatDateString, logger, errorToMessage, getRunDuration } from '../lib/Utils'; import { statusToIcon } from './Status'; -interface ExperimentInfo { - displayName?: string; - id: string; -} - interface PipelineInfo { displayName?: string; id?: string; @@ -386,13 +381,20 @@ class RunList extends React.PureComponent { private async _getAndSetExperimentNames(displayRun: DisplayRun): Promise { const experimentId = RunUtils.getFirstExperimentReferenceId(displayRun.run); if (experimentId) { - try { - const experiment = await Apis.experimentServiceApi.getExperiment(experimentId); - displayRun.experiment = { displayName: experiment.name || '', id: experimentId }; - } catch (err) { - // This could be an API exception, or a JSON parse exception. - displayRun.error = 'Failed to get associated experiment: ' + await errorToMessage(err); + let experimentName = RunUtils.getFirstExperimentReferenceName(displayRun.run); + if (!experimentName) { + try { + const experiment = await Apis.experimentServiceApi.getExperiment(experimentId); + experimentName = experiment.name || ''; + } catch (err) { + displayRun.error = 'Failed to get associated experiment: ' + await errorToMessage(err); + return; + } } + displayRun.experiment = { + displayName: experimentName, + id: experimentId + }; } } }