···168169// this is a mega query, but the most useful one:
170// get N pipelines, for each one get the latest status of its N workflows
171-func GetPipelineStatuses(e Execer, filters ...filter) ([]models.Pipeline, error) {
172 var conditions []string
173 var args []any
174 for _, filter := range filters {
···205 join
206 triggers t ON p.trigger_id = t.id
207 %s
208- `, whereClause)
00209210 rows, err := e.Query(query, args...)
211 if err != nil {
···168169// this is a mega query, but the most useful one:
170// get N pipelines, for each one get the latest status of its N workflows
171+func GetPipelineStatuses(e Execer, limit int, filters ...filter) ([]models.Pipeline, error) {
172 var conditions []string
173 var args []any
174 for _, filter := range filters {
···205 join
206 triggers t ON p.trigger_id = t.id
207 %s
208+ order by p.created desc
209+ limit %d
210+ `, whereClause, limit)
211212 rows, err := e.Query(query, args...)
213 if err != nil {
···1package repo
23import (
4- "crypto/rand"
5- "math/big"
6 "slices"
7 "sort"
8 "strings"
···90 return
91}
9293-func randomString(n int) string {
94- const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
95- result := make([]byte, n)
96-97- for i := 0; i < n; i++ {
98- n, _ := rand.Int(rand.Reader, big.NewInt(int64(len(letters))))
99- result[i] = letters[n.Int64()]
100- }
101-102- return string(result)
103-}
104-105// grab pipelines from DB and munge that into a hashmap with commit sha as key
106//
107// golang is so blessed that it requires 35 lines of imperative code for this
···118119 ps, err := db.GetPipelineStatuses(
120 d,
0121 db.FilterEq("repo_owner", repoInfo.OwnerDid),
122 db.FilterEq("repo_name", repoInfo.Name),
123 db.FilterEq("knot", repoInfo.Knot),
···1package repo
23import (
004 "slices"
5 "sort"
6 "strings"
···88 return
89}
9000000000000091// grab pipelines from DB and munge that into a hashmap with commit sha as key
92//
93// golang is so blessed that it requires 35 lines of imperative code for this
···104105 ps, err := db.GetPipelineStatuses(
106 d,
107+ len(shas),
108 db.FilterEq("repo_owner", repoInfo.OwnerDid),
109 db.FilterEq("repo_name", repoInfo.Name),
110 db.FilterEq("knot", repoInfo.Knot),