@@ -5,9 +5,10 @@ use crate::{
55 BenchmarkJobConclusion , BenchmarkJobStatus , BenchmarkRequest , BenchmarkRequestIndex ,
66 BenchmarkRequestStatus , BenchmarkRequestType , BenchmarkRequestWithErrors , BenchmarkSet ,
77 CodegenBackend , CollectionId , CollectorConfig , Commit , CommitType , CompileBenchmark , Date ,
8- Index , Profile , QueuedCommit , Scenario , Target , BENCHMARK_JOB_STATUS_FAILURE_STR ,
9- BENCHMARK_JOB_STATUS_IN_PROGRESS_STR , BENCHMARK_JOB_STATUS_QUEUED_STR ,
10- BENCHMARK_JOB_STATUS_SUCCESS_STR , BENCHMARK_REQUEST_MASTER_STR , BENCHMARK_REQUEST_RELEASE_STR ,
8+ Index , PendingBenchmarkRequests , Profile , QueuedCommit , Scenario , Target ,
9+ BENCHMARK_JOB_STATUS_FAILURE_STR , BENCHMARK_JOB_STATUS_IN_PROGRESS_STR ,
10+ BENCHMARK_JOB_STATUS_QUEUED_STR , BENCHMARK_JOB_STATUS_SUCCESS_STR ,
11+ BENCHMARK_REQUEST_MASTER_STR , BENCHMARK_REQUEST_RELEASE_STR ,
1112 BENCHMARK_REQUEST_STATUS_ARTIFACTS_READY_STR , BENCHMARK_REQUEST_STATUS_COMPLETED_STR ,
1213 BENCHMARK_REQUEST_STATUS_IN_PROGRESS_STR , BENCHMARK_REQUEST_STATUS_WAITING_FOR_ARTIFACTS_STR ,
1314 BENCHMARK_REQUEST_TRY_STR ,
@@ -500,6 +501,7 @@ pub struct CachedStatements {
500501 get_compile_test_cases_with_measurements : Statement ,
501502 get_last_n_completed_requests_with_errors : Statement ,
502503 get_jobs_of_in_progress_benchmark_requests : Statement ,
504+ load_pending_benchmark_requests : Statement ,
503505}
504506
505507pub struct PostgresTransaction < ' a > {
@@ -683,7 +685,7 @@ impl PostgresConnection {
683685 where aid = $1
684686 " ) . await . unwrap ( ) ,
685687 load_benchmark_request_index : conn. prepare ( "
686- SELECT tag, status
688+ SELECT tag
687689 FROM benchmark_request
688690 WHERE tag IS NOT NULL
689691 " ) . await . unwrap ( ) ,
@@ -751,6 +753,18 @@ impl PostgresConnection {
751753 -- Only get the jobs of in_progress requests
752754 SELECT * FROM job_queue INNER JOIN requests ON job_queue.request_tag = requests.tag
753755 " ) ) . await . unwrap ( ) ,
756+ // Load pending benchmark requests, along with information whether their parent is
757+ // completed or not
758+ load_pending_benchmark_requests : conn. prepare ( & format ! ( "
759+ WITH pending AS (
760+ SELECT {BENCHMARK_REQUEST_COLUMNS}
761+ FROM benchmark_request AS req
762+ WHERE status IN ('{BENCHMARK_REQUEST_STATUS_ARTIFACTS_READY_STR}', '{BENCHMARK_REQUEST_STATUS_IN_PROGRESS_STR}')
763+ )
764+ SELECT (parent.status = '{BENCHMARK_REQUEST_STATUS_COMPLETED_STR}') AS parent_done, pending.*
765+ FROM pending
766+ LEFT JOIN benchmark_request as parent ON parent.tag = pending.parent_sha
767+ " ) ) . await . unwrap ( ) ,
754768 } ) ,
755769 conn,
756770 }
@@ -809,7 +823,7 @@ where
809823 None => Date ( Utc . with_ymd_and_hms ( 2001 , 1 , 1 , 0 , 0 , 0 ) . unwrap ( ) ) ,
810824 }
811825 } ,
812- r#type : CommitType :: from_str ( & row. get :: < _ , String > ( 3 ) ) . unwrap ( )
826+ r#type : CommitType :: from_str ( & row. get :: < _ , String > ( 3 ) ) . unwrap ( ) ,
813827 } ,
814828 )
815829 } )
@@ -1188,13 +1202,13 @@ where
11881202 Some ( aid) => aid. get :: < _ , i32 > ( 0 ) as u32 ,
11891203 None => {
11901204 self . conn ( )
1191- . query_opt ( "insert into artifact (name, date, type) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING RETURNING id" , & [
1192- & info. name ,
1193- & info. date ,
1194- & info. kind ,
1195- ] )
1196- . await
1197- . unwrap ( ) ;
1205+ . query_opt ( "insert into artifact (name, date, type) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING RETURNING id" , & [
1206+ & info. name ,
1207+ & info. date ,
1208+ & info. kind ,
1209+ ] )
1210+ . await
1211+ . unwrap ( ) ;
11981212 self . conn ( )
11991213 . query_one ( "select id from artifact where name = $1" , & [ & info. name ] )
12001214 . await
@@ -1623,18 +1637,11 @@ where
16231637 . await
16241638 . context ( "Cannot load benchmark request index" ) ?;
16251639
1626- let mut all = HashSet :: with_capacity ( requests. len ( ) ) ;
1627- let mut completed = HashSet :: with_capacity ( requests. len ( ) ) ;
1628- for request in requests {
1629- let tag = request. get :: < _ , String > ( 0 ) ;
1630- let status = request. get :: < _ , & str > ( 1 ) ;
1631-
1632- if status == BENCHMARK_REQUEST_STATUS_COMPLETED_STR {
1633- completed. insert ( tag. clone ( ) ) ;
1634- }
1635- all. insert ( tag) ;
1636- }
1637- Ok ( BenchmarkRequestIndex { all, completed } )
1640+ let all = requests
1641+ . into_iter ( )
1642+ . map ( |row| row. get :: < _ , String > ( 0 ) )
1643+ . collect ( ) ;
1644+ Ok ( BenchmarkRequestIndex { all } )
16381645 }
16391646
16401647 async fn update_benchmark_request_status (
@@ -1705,25 +1712,30 @@ where
17051712 Ok ( ( ) )
17061713 }
17071714
1708- async fn load_pending_benchmark_requests ( & self ) -> anyhow:: Result < Vec < BenchmarkRequest > > {
1709- let query = format ! (
1710- r#"
1711- SELECT {BENCHMARK_REQUEST_COLUMNS}
1712- FROM benchmark_request
1713- WHERE status IN('{BENCHMARK_REQUEST_STATUS_ARTIFACTS_READY_STR}', '{BENCHMARK_REQUEST_STATUS_IN_PROGRESS_STR}')"#
1714- ) ;
1715-
1715+ async fn load_pending_benchmark_requests ( & self ) -> anyhow:: Result < PendingBenchmarkRequests > {
17161716 let rows = self
17171717 . conn ( )
1718- . query ( & query , & [ ] )
1718+ . query ( & self . statements ( ) . load_pending_benchmark_requests , & [ ] )
17191719 . await
17201720 . context ( "Failed to get pending benchmark requests" ) ?;
17211721
1722- let requests = rows
1723- . into_iter ( )
1724- . map ( |it| row_to_benchmark_request ( & it, None ) )
1725- . collect ( ) ;
1726- Ok ( requests)
1722+ let mut completed_parent_tags = HashSet :: new ( ) ;
1723+ let mut requests = Vec :: with_capacity ( rows. len ( ) ) ;
1724+ for row in rows {
1725+ let parent_done = row. get :: < _ , Option < bool > > ( 0 ) ;
1726+ let request = row_to_benchmark_request ( & row, Some ( 1 ) ) ;
1727+ if let Some ( true ) = parent_done {
1728+ if let Some ( parent) = request. parent_sha ( ) {
1729+ completed_parent_tags. insert ( parent. to_string ( ) ) ;
1730+ }
1731+ }
1732+ requests. push ( request) ;
1733+ }
1734+
1735+ Ok ( PendingBenchmarkRequests {
1736+ requests,
1737+ completed_parent_tags,
1738+ } )
17271739 }
17281740
17291741 async fn enqueue_benchmark_job (
0 commit comments