File tree 2 files changed +27
-3
lines changed
pages/compare/compile/table
2 files changed +27
-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
+ export class GraphResolver {
5
+ private cache : Dict < GraphData > = { } ;
6
+
7
+ public async loadGraph ( selector : GraphsSelector ) : Promise < GraphData > {
8
+ const key = `${ selector . benchmark } ;${ selector . profile } ;${ selector . scenario } ;${ selector . start } ;${ selector . end } ;${ selector . stat } ;${ selector . kind } ` ;
9
+ if ( ! this . cache . hasOwnProperty ( key ) ) {
10
+ this . cache [ key ] = await loadGraphs ( selector ) ;
11
+ }
12
+
13
+ return this . cache [ key ] ;
14
+ }
15
+ }
16
+
17
+ /**
18
+ * This is essentially a global variable, but it makes the code simpler and
19
+ * since we currently don't have any unit tests, we don't really need to avoid
20
+ * global variables that much. If needed, it could be provided to Vue components
21
+ * from a parent via props or context.
22
+ */
23
+ export const GRAPH_RESOLVER = new GraphResolver ( ) ;
Original file line number Diff line number Diff line change @@ -7,10 +7,11 @@ import {
7
7
} from " ../common" ;
8
8
import {computed , onMounted , Ref , ref } from " vue" ;
9
9
import Tooltip from " ../../tooltip.vue" ;
10
- import {loadGraphs } from " ../../../../graph/api" ;
11
10
import {ArtifactDescription } from " ../../types" ;
12
11
import {getDateInPast } from " ./utils" ;
13
12
import {renderPlots } from " ../../../../graph/render" ;
13
+ import {GRAPH_RESOLVER } from " ../../../../graph/resolver" ;
14
+ import {GraphKind } from " ../../../../graph/data" ;
14
15
15
16
const props = defineProps <{
16
17
testCase: CompileTestCase ;
@@ -27,9 +28,9 @@ async function renderGraph() {
27
28
stat: props .metric ,
28
29
start: getDateInPast (props .artifact ),
29
30
end: props .artifact .commit ,
30
- kind: " raw" ,
31
+ kind: " raw" as GraphKind ,
31
32
};
32
- const graphData = await loadGraphs (selector );
33
+ const graphData = await GRAPH_RESOLVER . loadGraph (selector );
33
34
renderPlots (graphData , selector , chartElement .value , {
34
35
renderTitle: false ,
35
36
});
You can’t perform that action at this time.
0 commit comments