Skip to content

Commit de2e255

Browse files
Merge pull request #3642 from mstaeble/optimize-job-run-test-count
Add timestamp to JobRunTestCount for partition pruning
2 parents 4fbbcfe + 550c601 commit de2e255

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

pkg/api/job_runs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func FetchJobRun(dbc *db.DB, jobRunID int64, unknownTests bool, preloads []strin
203203
return nil, res.Error
204204
}
205205

206-
jobRunTestCount, err := query.JobRunTestCount(dbc, jobRunID, jobRun.ProwJobRelease)
206+
jobRunTestCount, err := query.JobRunTestCount(dbc, jobRunID, jobRun.ProwJobRelease, jobRun.Timestamp)
207207
if err != nil { // should be unusual
208208
logger.WithError(err).Errorf("Error getting test count for job run %d", jobRunID)
209209
jobRunTestCount = -1

pkg/db/query/job_queries.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ func LoadProwJobCache(dbc *db.DB) (map[string]*models.ProwJob, error) {
2828
return prowJobCache, nil
2929
}
3030

31-
func JobRunTestCount(dbc *db.DB, jobRunID int64, release string) (int, error) {
31+
func JobRunTestCount(dbc *db.DB, jobRunID int64, release string, timestamp time.Time) (int, error) {
3232
var prowJobRunTestCount int64
3333

3434
res := dbc.DB.Model(&models.ProwJobRunTest{}).
3535
Where("prow_job_run_id = ?", jobRunID).
3636
Where("prow_job_run_release = ?", release).
37+
Where("prow_job_run_timestamp = ?", timestamp).
3738
Count(&prowJobRunTestCount)
3839
if res.Error != nil {
3940
return -1, res.Error

pkg/flags/postgres_benchmarking_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,20 +415,23 @@ func getBenchmarkCases(asOf time.Time) []benchmarkCase {
415415
{
416416
name: "JobRunTestCount",
417417
fn: func(dbc *db.DB) error {
418-
var jobRunID int64
418+
var result struct {
419+
ID int64
420+
Timestamp time.Time
421+
}
419422
res := dbc.DB.Table("prow_job_runs").
420423
Joins("JOIN prow_jobs ON prow_jobs.id = prow_job_runs.prow_job_id").
421424
Where("prow_jobs.name = ? AND prow_jobs.release = ?", benchmarkJobName, benchmarkRelease).
422425
Order("prow_job_runs.timestamp DESC").
423426
Limit(1).
424-
Select("prow_job_runs.id").
425-
Scan(&jobRunID)
427+
Select("prow_job_runs.id, prow_job_runs.timestamp").
428+
Scan(&result)
426429
if res.Error != nil {
427430
return res.Error
428431
}
429-
count, err := query.JobRunTestCount(dbc, jobRunID, benchmarkRelease)
432+
count, err := query.JobRunTestCount(dbc, result.ID, benchmarkRelease, result.Timestamp)
430433
if err == nil {
431-
log.Printf("JobRunTestCount for run %d: %d tests", jobRunID, count)
434+
log.Printf("JobRunTestCount for run %d: %d tests", result.ID, count)
432435
}
433436
return err
434437
},

0 commit comments

Comments
 (0)