Remove unnecessary rows.Close() calls
This commit is contained in:
parent
ac43ef4ab7
commit
fece11540b
@ -461,11 +461,8 @@ func (s *Store) updateServiceUptime(tx *sql.Tx, serviceID int64, result *core.Re
|
|||||||
successfulExecutions,
|
successfulExecutions,
|
||||||
result.Duration.Milliseconds(),
|
result.Duration.Milliseconds(),
|
||||||
)
|
)
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Store) getAllServiceKeys(tx *sql.Tx) (keys []string, err error) {
|
func (s *Store) getAllServiceKeys(tx *sql.Tx) (keys []string, err error) {
|
||||||
rows, err := tx.Query("SELECT service_key FROM service ORDER BY service_key")
|
rows, err := tx.Query("SELECT service_key FROM service ORDER BY service_key")
|
||||||
@ -477,7 +474,6 @@ func (s *Store) getAllServiceKeys(tx *sql.Tx) (keys []string, err error) {
|
|||||||
_ = rows.Scan(&key)
|
_ = rows.Scan(&key)
|
||||||
keys = append(keys, key)
|
keys = append(keys, key)
|
||||||
}
|
}
|
||||||
_ = rows.Close()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,7 +542,6 @@ func (s *Store) getEventsByServiceID(tx *sql.Tx, serviceID int64, page, pageSize
|
|||||||
_ = rows.Scan(&event.Type, &event.Timestamp)
|
_ = rows.Scan(&event.Type, &event.Timestamp)
|
||||||
events = append(events, event)
|
events = append(events, event)
|
||||||
}
|
}
|
||||||
_ = rows.Close()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -579,7 +574,6 @@ func (s *Store) getResultsByServiceID(tx *sql.Tx, serviceID int64, page, pageSiz
|
|||||||
results = append([]*core.Result{result}, results...)
|
results = append([]*core.Result{result}, results...)
|
||||||
idResultMap[id] = result
|
idResultMap[id] = result
|
||||||
}
|
}
|
||||||
_ = rows.Close()
|
|
||||||
// Get condition results
|
// Get condition results
|
||||||
args := make([]interface{}, 0, len(idResultMap))
|
args := make([]interface{}, 0, len(idResultMap))
|
||||||
query := `SELECT service_result_id, condition, success
|
query := `SELECT service_result_id, condition, success
|
||||||
@ -596,6 +590,7 @@ func (s *Store) getResultsByServiceID(tx *sql.Tx, serviceID int64, page, pageSiz
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
defer rows.Close() // explicitly defer the close in case an error happens during the scan
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
conditionResult := &core.ConditionResult{}
|
conditionResult := &core.ConditionResult{}
|
||||||
var serviceResultID int64
|
var serviceResultID int64
|
||||||
@ -626,9 +621,7 @@ func (s *Store) getServiceUptime(tx *sql.Tx, serviceID int64, from, to time.Time
|
|||||||
var totalExecutions, totalSuccessfulExecutions, totalResponseTime int
|
var totalExecutions, totalSuccessfulExecutions, totalResponseTime int
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
_ = rows.Scan(&totalExecutions, &totalSuccessfulExecutions, &totalResponseTime)
|
_ = rows.Scan(&totalExecutions, &totalSuccessfulExecutions, &totalResponseTime)
|
||||||
break
|
|
||||||
}
|
}
|
||||||
_ = rows.Close()
|
|
||||||
if totalExecutions > 0 {
|
if totalExecutions > 0 {
|
||||||
uptime = float64(totalSuccessfulExecutions) / float64(totalExecutions)
|
uptime = float64(totalSuccessfulExecutions) / float64(totalExecutions)
|
||||||
avgResponseTime = time.Duration(float64(totalResponseTime)/float64(totalExecutions)) * time.Millisecond
|
avgResponseTime = time.Duration(float64(totalResponseTime)/float64(totalExecutions)) * time.Millisecond
|
||||||
@ -657,7 +650,6 @@ func (s *Store) getServiceAverageResponseTime(tx *sql.Tx, serviceID int64, from,
|
|||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
_ = rows.Scan(&totalExecutions, &totalResponseTime)
|
_ = rows.Scan(&totalExecutions, &totalResponseTime)
|
||||||
}
|
}
|
||||||
_ = rows.Close()
|
|
||||||
if totalExecutions == 0 {
|
if totalExecutions == 0 {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
@ -688,7 +680,6 @@ func (s *Store) getServiceHourlyAverageResponseTimes(tx *sql.Tx, serviceID int64
|
|||||||
_ = rows.Scan(&unixTimestampFlooredAtHour, &totalExecutions, &totalResponseTime)
|
_ = rows.Scan(&unixTimestampFlooredAtHour, &totalExecutions, &totalResponseTime)
|
||||||
hourlyAverageResponseTimes[unixTimestampFlooredAtHour] = int(float64(totalResponseTime) / float64(totalExecutions))
|
hourlyAverageResponseTimes[unixTimestampFlooredAtHour] = int(float64(totalResponseTime) / float64(totalExecutions))
|
||||||
}
|
}
|
||||||
_ = rows.Close()
|
|
||||||
return hourlyAverageResponseTimes, nil
|
return hourlyAverageResponseTimes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -735,9 +726,7 @@ func (s *Store) getAgeOfOldestServiceUptimeEntry(tx *sql.Tx, serviceID int64) (t
|
|||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
_ = rows.Scan(&oldestServiceUptimeUnixTimestamp)
|
_ = rows.Scan(&oldestServiceUptimeUnixTimestamp)
|
||||||
found = true
|
found = true
|
||||||
break
|
|
||||||
}
|
}
|
||||||
_ = rows.Close()
|
|
||||||
if !found {
|
if !found {
|
||||||
return 0, errNoRowsReturned
|
return 0, errNoRowsReturned
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user