File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change 11use  std:: collections:: HashMap ; 
2- use  std:: path:: Path ; 
2+ use  std:: path:: { Path ,   PathBuf } ; 
33
44use  anyhow:: Context ; 
55use  build_helper:: metrics:: { JsonNode ,  JsonRoot ,  TestSuite } ; 
@@ -74,6 +74,17 @@ Maybe it was newly added?"#,
7474} 
7575
7676pub  fn  download_job_metrics ( job_name :  & str ,  sha :  & str )  -> anyhow:: Result < JsonRoot >  { 
77+     // Best effort cache to speed-up local re-executions of citool 
78+     let  cache_path = PathBuf :: from ( ".citool-cache" ) . join ( sha) . join ( format ! ( "{job_name}.json" ) ) ; 
79+     if  cache_path. is_file ( )  { 
80+         if  let  Ok ( metrics)  = std:: fs:: read_to_string ( & cache_path) 
81+             . map_err ( |err| err. into ( ) ) 
82+             . and_then ( |data| anyhow:: Ok :: < JsonRoot > ( serde_json:: from_str :: < JsonRoot > ( & data) ?) ) 
83+         { 
84+             return  Ok ( metrics) ; 
85+         } 
86+     } 
87+ 
7788    let  url = get_metrics_url ( job_name,  sha) ; 
7889    let  mut  response = ureq:: get ( & url) . call ( ) ?; 
7990    if  !response. status ( ) . is_success ( )  { 
@@ -87,6 +98,13 @@ pub fn download_job_metrics(job_name: &str, sha: &str) -> anyhow::Result<JsonRoo
8798        . body_mut ( ) 
8899        . read_json ( ) 
89100        . with_context ( || anyhow:: anyhow!( "cannot deserialize metrics from {url}" ) ) ?; 
101+ 
102+     if  let  Ok ( _)  = std:: fs:: create_dir_all ( cache_path. parent ( ) . unwrap ( ) )  { 
103+         if  let  Ok ( data)  = serde_json:: to_string ( & data)  { 
104+             let  _ = std:: fs:: write ( cache_path,  data) ; 
105+         } 
106+     } 
107+ 
90108    Ok ( data) 
91109} 
92110
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments