Skip to content

Commit

Permalink
parallel query runs and results
Browse files Browse the repository at this point in the history
Signed-off-by: robinbraemer <[email protected]>
  • Loading branch information
robinbraemer committed Oct 18, 2024
1 parent 95cb9b6 commit 0c242a0
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions pkg/storage/installation_store_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"go.mongodb.org/mongo-driver/bson"
"golang.org/x/sync/errgroup"
"gorm.io/gorm"

"get.porter.sh/porter/pkg/tracing"
Expand Down Expand Up @@ -99,16 +100,23 @@ func (s *InstallationStoreSQL) ListRuns(ctx context.Context, namespace string, i
var runs []Run
var results []Result

err := s.db.WithContext(ctx).Where("namespace = ? AND installation = ?", namespace, installation).Order("id").Find(&runs).Error
if err != nil {
eg, ctx := errgroup.WithContext(ctx)
eg.Go(func() error {
return s.db.WithContext(ctx).
Where("namespace = ? AND installation = ?", namespace, installation).
Order("id").
Find(&runs).Error
})
eg.Go(func() error {
return s.db.WithContext(ctx).
Where("namespace = ? AND installation = ?", namespace, installation).
Order("run_id, id").
Find(&results).Error
})
if err := eg.Wait(); err != nil {
return nil, nil, err
}

err = s.db.WithContext(ctx).Where("namespace = ? AND installation = ?", namespace, installation).Find(&results).Error
if err != nil {
return runs, nil, err
}

resultsMap := make(map[string][]Result, len(runs))
for _, run := range runs {
resultsMap[run.ID] = []Result{}
Expand Down Expand Up @@ -152,7 +160,7 @@ func (s *InstallationStoreSQL) FindInstallations(ctx context.Context, findOpts F
// Assume it's a label query
if strings.HasPrefix(key, "labels.") {
labelKey := strings.TrimPrefix(key, "labels.")
query = query.Where("labels->? @> ?", labelKey, fmt.Sprintf("\"%v\"", value))
query = query.Where("labels->? @> ?", labelKey, fmt.Sprintf(`%q`, value))
}
}
}
Expand Down

0 comments on commit 0c242a0

Please sign in to comment.