1
1
import { GraphKind , Series } from "../../../../graph/data" ;
2
2
import { getJson } from "../../../../utils/requests" ;
3
- import { COMPARE_COMPILE_DETAIL_DATA_URL } from "../../../../urls" ;
3
+ import { COMPARE_COMPILE_DETAIL_GRAPHS_DATA_URL } from "../../../../urls" ;
4
+ import { CachedDataLoader } from "./utils" ;
4
5
5
- export interface CompileDetailSelector {
6
+ export interface CompileDetailGraphsSelector {
6
7
start : string ;
7
8
end : string ;
8
9
stat : string ;
@@ -13,7 +14,7 @@ export interface CompileDetailSelector {
13
14
}
14
15
15
16
// Compile benchmark detail received from the server
16
- export interface CompileDetail {
17
+ export interface CompileDetailGraphs {
17
18
commits : Array < [ number , string ] > ;
18
19
// One Series for each GraphKind in the CompileDetailSelector
19
20
graphs : Series [ ] ;
@@ -24,33 +25,23 @@ export interface CompileDetail {
24
25
* This is important for Vue components that download the benchmark detail on mount.
25
26
* Without a cache, they would download the detail each time they are destroyed
26
27
* and recreated.
27
- */
28
- export class CompileBenchmarkDetailResolver {
29
- private cache : Dict < CompileDetail > = { } ;
30
-
31
- public async loadDetail (
32
- selector : CompileDetailSelector
33
- ) : Promise < CompileDetail > {
34
- const key = `${ selector . benchmark } ;${ selector . profile } ;${ selector . scenario } ;${ selector . start } ;${ selector . end } ;${ selector . stat } ;${ selector . kinds } ` ;
35
- if ( ! this . cache . hasOwnProperty ( key ) ) {
36
- this . cache [ key ] = await loadDetail ( selector ) ;
37
- }
38
-
39
- return this . cache [ key ] ;
40
- }
41
- }
42
-
43
- /**
44
28
* This is essentially a global variable, but it makes the code simpler and
45
29
* since we currently don't have any unit tests, we don't really need to avoid
46
30
* global variables that much. If needed, it could be provided to Vue components
47
31
* from a parent via props or context.
48
32
*/
49
- export const COMPILE_DETAIL_RESOLVER = new CompileBenchmarkDetailResolver ( ) ;
33
+ export const COMPILE_DETAIL_GRAPHS_RESOLVER : CachedDataLoader <
34
+ CompileDetailGraphsSelector ,
35
+ CompileDetailGraphs
36
+ > = new CachedDataLoader (
37
+ ( key : CompileDetailGraphsSelector ) =>
38
+ `${ key . benchmark } ;${ key . profile } ;${ key . scenario } ;${ key . start } ;${ key . end } ;${ key . stat } ;${ key . kinds } ` ,
39
+ loadDetail
40
+ ) ;
50
41
51
42
async function loadDetail (
52
- selector : CompileDetailSelector
53
- ) : Promise < CompileDetail > {
43
+ selector : CompileDetailGraphsSelector
44
+ ) : Promise < CompileDetailGraphs > {
54
45
const params = {
55
46
start : selector . start ,
56
47
end : selector . end ,
@@ -60,5 +51,8 @@ async function loadDetail(
60
51
profile : selector . profile ,
61
52
kinds : selector . kinds . join ( "," ) ,
62
53
} ;
63
- return await getJson < CompileDetail > ( COMPARE_COMPILE_DETAIL_DATA_URL , params ) ;
54
+ return await getJson < CompileDetailGraphs > (
55
+ COMPARE_COMPILE_DETAIL_GRAPHS_DATA_URL ,
56
+ params
57
+ ) ;
64
58
}
0 commit comments