diff mbox series

[OSSTEST,55/60] history reporting: Break out minflight_by_time

Message ID 20200814172205.9624-56-ian.jackson@eu.citrix.com (mailing list archive)
State New, archived
Headers show
Series Speed up sg-report-job-history | expand

Commit Message

Ian Jackson Aug. 14, 2020, 5:22 p.m. UTC
Move this from sg-report-host-history so we can reuse it.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
---
 Osstest/HistoryReport.pm | 16 ++++++++++++++++
 sg-report-host-history   | 13 ++-----------
 2 files changed, 18 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/Osstest/HistoryReport.pm b/Osstest/HistoryReport.pm
index 3e2ad0d3..b851ae45 100644
--- a/Osstest/HistoryReport.pm
+++ b/Osstest/HistoryReport.pm
@@ -37,6 +37,7 @@  BEGIN {
 			 cache_write_entry
 			 cache_finish
 			 parallel_by_fork
+			 minflight_by_time
 		    );
     %EXPORT_TAGS = ();
 
@@ -282,4 +283,19 @@  sub parallel_by_fork ($$$$) {
     exit $worst;
 }
 
+sub minflight_by_time ($) {
+    my ($timelimit) = @_;
+    my $minflightsq = db_prepare(<<END);
+	    SELECT flight
+              FROM flights
+             WHERE started >= ?
+          ORDER BY flight ASC
+             LIMIT 1
+END
+    my $now = time // die $!;
+    $minflightsq->execute($now - $timelimit);
+    my ($minflight,) = $minflightsq->fetchrow_array();
+    $minflight //= 0;
+}
+
 1;
diff --git a/sg-report-host-history b/sg-report-host-history
index 0a2e9904..efe652bb 100755
--- a/sg-report-host-history
+++ b/sg-report-host-history
@@ -95,19 +95,10 @@  sub computeflightsrange () {
 END
 	$minflightsq->execute();
 	($minflight,) = $minflightsq->fetchrow_array();
+	$minflight //= 0;
     } else {
-	my $minflightsq = db_prepare(<<END);
-	    SELECT flight
-              FROM flights
-             WHERE started >= ?
-          ORDER BY flight ASC
-             LIMIT 1
-END
-	my $now = time // die $!;
-        $minflightsq->execute($now - $timelimit);
-	($minflight,) = $minflightsq->fetchrow_array();
+	$minflight = minflight_by_time($timelimit);
     }
-    $minflight //= 0;
 
     $flightcond = "(flight > $minflight)";