From 32e27b7b38ee8ff6b6044608d3c271d506651f36 Mon Sep 17 00:00:00 2001 From: dusk Date: Tue, 12 Aug 2025 18:02:21 +0300 Subject: [PATCH] appview: db: pulls: add method for getting any pulls on a repo Change-Id: vpswvtqqqqlkzmwtvkuotykmoooqmwou Signed-off-by: dusk --- appview/db/pulls.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/appview/db/pulls.go b/appview/db/pulls.go index e993791..9c954f2 100644 --- a/appview/db/pulls.go +++ b/appview/db/pulls.go @@ -310,7 +310,7 @@ func NextPullId(e Execer, repoAt syntax.ATURI) (int, error) { return pullId - 1, err } -func GetPulls(e Execer, filters ...filter) ([]*Pull, error) { +func GetPullsWithLimit(e Execer, limit int, filters ...filter) ([]*Pull, error) { pulls := make(map[int]*Pull) var conditions []string @@ -324,6 +324,10 @@ func GetPulls(e Execer, filters ...filter) ([]*Pull, error) { if conditions != nil { whereClause = " where " + strings.Join(conditions, " and ") } + limitClause := "" + if limit != 0 { + limitClause = fmt.Sprintf(" limit %d ", limit) + } query := fmt.Sprintf(` select @@ -344,7 +348,10 @@ func GetPulls(e Execer, filters ...filter) ([]*Pull, error) { from pulls %s - `, whereClause) + order by + created desc + %s + `, whereClause, limitClause) rows, err := e.Query(query, args...) if err != nil { @@ -513,6 +520,10 @@ func GetPulls(e Execer, filters ...filter) ([]*Pull, error) { return orderedByPullId, nil } +func GetPulls(e Execer, filters ...filter) ([]*Pull, error) { + return GetPullsWithLimit(e, 0, filters...) +} + func GetPull(e Execer, repoAt syntax.ATURI, pullId int) (*Pull, error) { query := ` select -- 2.43.0