Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return resource count from ListXXX calls #595

Merged
merged 17 commits into from
Jan 31, 2019
Prev Previous commit
Next Next commit
close db rows before second query
  • Loading branch information
Yasser Elsayed committed Jan 24, 2019
commit 9ac96c5d7dcf7015be1646c54d4675c04aab1b36
10 changes: 4 additions & 6 deletions backend/src/apiserver/storage/experiment_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,24 @@ func (s *ExperimentStore) ListExperiments(opts *list.Options) ([]*model.Experime
tx.Rollback()
return errorF(err)
}
defer rows.Close()

countRow, err := tx.Query(countSql, countArgs...)
exps, err := s.scanRows(rows)
if err != nil {
tx.Rollback()
return errorF(err)
}
defer rows.Close()
rows.Close()
yebrahim marked this conversation as resolved.
Show resolved Hide resolved

exps, err := s.scanRows(rows)
countRow, err := tx.Query(countSql, countArgs...)
if err != nil {
tx.Rollback()
return errorF(err)
}

count, err := s.scanRowToCount(countRow)
if err != nil {
tx.Rollback()
return errorF(err)
}
countRow.Close()

tx.Commit()
if err != nil {
Expand Down
10 changes: 4 additions & 6 deletions backend/src/apiserver/storage/job_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,24 @@ func (s *JobStore) ListJobs(
tx.Rollback()
return errorF(err)
}
defer rows.Close()

countRow, err := tx.Query(countSql, countArgs...)
jobs, err := s.scanRows(rows)
if err != nil {
tx.Rollback()
return errorF(err)
}
defer countRow.Close()
rows.Close()

jobs, err := s.scanRows(rows)
countRow, err := tx.Query(countSql, countArgs...)
if err != nil {
tx.Rollback()
return errorF(err)
}

count, err := s.scanRowToCount(countRow)
if err != nil {
tx.Rollback()
return errorF(err)
}
countRow.Close()

tx.Commit()
if err != nil {
yebrahim marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
10 changes: 4 additions & 6 deletions backend/src/apiserver/storage/pipeline_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,24 @@ func (s *PipelineStore) ListPipelines(opts *list.Options) ([]*model.Pipeline, in
tx.Rollback()
return errorF(err)
}
defer rows.Close()

countRow, err := tx.Query(countSql, countArgs...)
pipelines, err := s.scanRows(rows)
if err != nil {
tx.Rollback()
return errorF(err)
}
defer rows.Close()
rows.Close()

pipelines, err := s.scanRows(rows)
countRow, err := tx.Query(countSql, countArgs...)
if err != nil {
tx.Rollback()
return errorF(err)
}

count, err := s.scanRowToCount(countRow)
if err != nil {
tx.Rollback()
return errorF(err)
}
countRow.Close()

tx.Commit()
if err != nil {
Expand Down
10 changes: 4 additions & 6 deletions backend/src/apiserver/storage/run_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,24 @@ func (s *RunStore) ListRuns(
tx.Rollback()
return errorF(err)
}
defer rows.Close()

countRow, err := tx.Query(countSql, countArgs...)
runDetails, err := s.scanRowsToRunDetails(rows)
if err != nil {
tx.Rollback()
return errorF(err)
}
defer countRow.Close()
rows.Close()

runDetails, err := s.scanRowsToRunDetails(rows)
countRow, err := tx.Query(countSql, countArgs...)
if err != nil {
tx.Rollback()
return errorF(err)
}

count, err := s.scanRowToCount(countRow)
if err != nil {
tx.Rollback()
return errorF(err)
}
countRow.Close()

tx.Commit()
if err != nil {
Expand Down