File tree Expand file tree Collapse file tree 2 files changed +33
-3
lines changed
pages/compare/compile/table Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Original file line number Diff line number Diff line change 1+ import { GraphData , GraphsSelector } from "./data" ;
2+ import { loadGraphs } from "./api" ;
3+
4+ /**
5+ * Graph API resolver that contains a cache of downloaded graphs.
6+ * This is important for Vue components that download a graph on mount.
7+ * Without a cache, they would download a graph each time they are destroyed
8+ * and recreated.
9+ */
10+ export class GraphResolver {
11+ private cache : Dict < GraphData > = { } ;
12+
13+ public async loadGraph ( selector : GraphsSelector ) : Promise < GraphData > {
14+ const key = `${ selector . benchmark } ;${ selector . profile } ;${ selector . scenario } ;${ selector . start } ;${ selector . end } ;${ selector . stat } ;${ selector . kind } ` ;
15+ if ( ! this . cache . hasOwnProperty ( key ) ) {
16+ this . cache [ key ] = await loadGraphs ( selector ) ;
17+ }
18+
19+ return this . cache [ key ] ;
20+ }
21+ }
22+
23+ /**
24+ * This is essentially a global variable, but it makes the code simpler and
25+ * since we currently don't have any unit tests, we don't really need to avoid
26+ * global variables that much. If needed, it could be provided to Vue components
27+ * from a parent via props or context.
28+ */
29+ export const GRAPH_RESOLVER = new GraphResolver ( ) ;
Original file line number Diff line number Diff line change @@ -7,10 +7,11 @@ import {
77} from " ../common" ;
88import {computed , onMounted , Ref , ref } from " vue" ;
99import Tooltip from " ../../tooltip.vue" ;
10- import {loadGraphs } from " ../../../../graph/api" ;
1110import {ArtifactDescription } from " ../../types" ;
1211import {getDateInPast } from " ./utils" ;
1312import {renderPlots } from " ../../../../graph/render" ;
13+ import {GRAPH_RESOLVER } from " ../../../../graph/resolver" ;
14+ import {GraphKind } from " ../../../../graph/data" ;
1415
1516const props = defineProps <{
1617 testCase: CompileTestCase ;
@@ -27,9 +28,9 @@ async function renderGraph() {
2728 stat: props .metric ,
2829 start: getDateInPast (props .artifact ),
2930 end: props .artifact .commit ,
30- kind: " raw" ,
31+ kind: " raw" as GraphKind ,
3132 };
32- const graphData = await loadGraphs (selector );
33+ const graphData = await GRAPH_RESOLVER . loadGraph (selector );
3334 renderPlots (graphData , selector , chartElement .value , {
3435 renderTitle: false ,
3536 });
You can’t perform that action at this time.
0 commit comments