···170170171171// this is a mega query, but the most useful one:172172// get N pipelines, for each one get the latest status of its N workflows173173+//174174+// the pipelines table is aliased to `p`175175+// the triggers table is aliased to `t`173176func GetPipelineStatuses(e Execer, limit int, filters ...orm.Filter) ([]models.Pipeline, error) {174177 var conditions []string175178 var args []any176179 for _, filter := range filters {177177- filter.Key = "p." + filter.Key // the table is aliased in the query to `p`178180 conditions = append(conditions, filter.Condition())179181 args = append(args, filter.Arg()...)180182 }···367365 })368366369367 return all, nil368368+}369369+370370+// the pipelines table is aliased to `p`371371+// the triggers table is aliased to `t`372372+func GetTotalPipelineStatuses(e Execer, filters ...orm.Filter) (int64, error) {373373+ var conditions []string374374+ var args []any375375+ for _, filter := range filters {376376+ conditions = append(conditions, filter.Condition())377377+ args = append(args, filter.Arg()...)378378+ }379379+380380+ whereClause := ""381381+ if conditions != nil {382382+ whereClause = " where " + strings.Join(conditions, " and ")383383+ }384384+385385+ query := fmt.Sprintf(`386386+ select387387+ count(1)388388+ from389389+ pipelines p390390+ join391391+ triggers t ON p.trigger_id = t.id392392+ %s393393+ `, whereClause)394394+395395+ rows, err := e.Query(query, args...)396396+ if err != nil {397397+ return 0, err398398+ }399399+ defer rows.Close()400400+401401+ for rows.Next() {402402+ var count int64403403+ err := rows.Scan(&count)404404+ if err != nil {405405+ return 0, err406406+ }407407+408408+ return count, nil409409+ }410410+411411+ // unreachable412412+ return 0, nil370413}