fix: Add defer.close for all queries

This commit is contained in:
2026-03-11 05:04:20 +01:00
parent f9aa47ea1c
commit 5d3d77620e
12 changed files with 709 additions and 35 deletions

View File

@@ -159,6 +159,7 @@ func (r *JobRepository) JobsStatsGrouped(
cclog.Warn("Error while querying DB for job statistics")
return nil, err
}
defer rows.Close()
stats := make([]*model.JobsStatistics, 0, 100)
@@ -244,6 +245,10 @@ func (r *JobRepository) JobsStatsGrouped(
}
}
if err := rows.Err(); err != nil {
return nil, err
}
cclog.Debugf("Timer JobsStatsGrouped %s", time.Since(start))
return stats, nil
}
@@ -329,6 +334,7 @@ func (r *JobRepository) JobCountGrouped(
cclog.Warn("Error while querying DB for job statistics")
return nil, err
}
defer rows.Close()
stats := make([]*model.JobsStatistics, 0, 100)
@@ -348,6 +354,10 @@ func (r *JobRepository) JobCountGrouped(
}
}
if err := rows.Err(); err != nil {
return nil, err
}
cclog.Debugf("Timer JobCountGrouped %s", time.Since(start))
return stats, nil
}
@@ -371,6 +381,7 @@ func (r *JobRepository) AddJobCountGrouped(
cclog.Warn("Error while querying DB for job statistics")
return nil, err
}
defer rows.Close()
counts := make(map[string]int)
@@ -386,6 +397,10 @@ func (r *JobRepository) AddJobCountGrouped(
}
}
if err := rows.Err(); err != nil {
return nil, err
}
switch kind {
case "running":
for _, s := range stats {
@@ -413,23 +428,13 @@ func (r *JobRepository) AddJobCount(
if err != nil {
return nil, err
}
rows, err := query.RunWith(r.DB).Query()
if err != nil {
cclog.Warn("Error while querying DB for job statistics")
var cnt sql.NullInt64
if err := query.RunWith(r.DB).QueryRow().Scan(&cnt); err != nil {
cclog.Warn("Error while querying DB for job count")
return nil, err
}
var count int
for rows.Next() {
var cnt sql.NullInt64
if err := rows.Scan(&cnt); err != nil {
cclog.Warn("Error while scanning rows")
return nil, err
}
count = int(cnt.Int64)
}
count := int(cnt.Int64)
switch kind {
case "running":
@@ -567,6 +572,7 @@ func (r *JobRepository) jobsStatisticsHistogram(
cclog.Error("Error while running query")
return nil, err
}
defer rows.Close()
points := make([]*model.HistoPoint, 0)
// is it possible to introduce zero values here? requires info about bincount
@@ -579,6 +585,11 @@ func (r *JobRepository) jobsStatisticsHistogram(
points = append(points, &point)
}
if err := rows.Err(); err != nil {
return nil, err
}
cclog.Debugf("Timer jobsStatisticsHistogram %s", time.Since(start))
return points, nil
}
@@ -614,6 +625,7 @@ func (r *JobRepository) jobsDurationStatisticsHistogram(
cclog.Error("Error while running query")
return nil, err
}
defer rows.Close()
// Fill Array at matching $Value
for rows.Next() {
@@ -634,6 +646,10 @@ func (r *JobRepository) jobsDurationStatisticsHistogram(
}
}
if err := rows.Err(); err != nil {
return nil, err
}
cclog.Debugf("Timer jobsStatisticsHistogram %s", time.Since(start))
return points, nil
}
@@ -716,6 +732,7 @@ func (r *JobRepository) jobsMetricStatisticsHistogram(
cclog.Errorf("Error while running mainQuery: %s", err)
return nil, err
}
defer rows.Close()
// Setup Return Array With Bin-Numbers for Match and Min/Max based on Peak
points := make([]*model.MetricHistoPoint, 0)
@@ -751,6 +768,10 @@ func (r *JobRepository) jobsMetricStatisticsHistogram(
}
}
if err := rows.Err(); err != nil {
return nil, err
}
result := model.MetricHistoPoints{Metric: metric, Unit: unit, Stat: &footprintStat, Data: points}
cclog.Debugf("Timer jobsStatisticsHistogram %s", time.Since(start))