Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2 (Please be gentle).
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

appview: db: issues: add method for getting any issues a repo might have

Signed-off-by: dusk <y.bera003.06@protonmail.com>

authored by

dusk and committed by
Tangled
b3ce5aec 3f7f0cfd

+85 -4
+84 -3
appview/db/issues.go
··· 3 3 import ( 4 4 "database/sql" 5 5 "fmt" 6 + "strings" 6 7 "time" 7 8 8 9 "github.com/bluesky-social/indigo/atproto/syntax" ··· 106 105 return ownerDid, err 107 106 } 108 107 109 - func GetIssues(e Execer, repoAt syntax.ATURI, isOpen bool, page pagination.Page) ([]Issue, error) { 108 + func GetIssuesPaginated(e Execer, repoAt syntax.ATURI, isOpen bool, page pagination.Page) ([]Issue, error) { 110 109 var issues []Issue 111 110 openValue := 0 112 111 if isOpen { ··· 146 145 body, 147 146 open, 148 147 comment_count 149 - from 148 + from 150 149 numbered_issue 151 - where 150 + where 152 151 row_num between ? and ?`, 153 152 repoAt, openValue, page.Offset+1, page.Offset+page.Limit) 154 153 if err != nil { ··· 180 179 } 181 180 182 181 return issues, nil 182 + } 183 + 184 + func GetIssuesWithLimit(e Execer, limit int, filters ...filter) ([]Issue, error) { 185 + issues := make([]Issue, 0, limit) 186 + 187 + var conditions []string 188 + var args []any 189 + for _, filter := range filters { 190 + conditions = append(conditions, filter.Condition()) 191 + args = append(args, filter.Arg()...) 192 + } 193 + 194 + whereClause := "" 195 + if conditions != nil { 196 + whereClause = " where " + strings.Join(conditions, " and ") 197 + } 198 + limitClause := "" 199 + if limit != 0 { 200 + limitClause = fmt.Sprintf(" limit %d ", limit) 201 + } 202 + 203 + query := fmt.Sprintf( 204 + `select 205 + i.id, 206 + i.owner_did, 207 + i.repo_at, 208 + i.issue_id, 209 + i.created, 210 + i.title, 211 + i.body, 212 + i.open 213 + from 214 + issues i 215 + %s 216 + order by 217 + i.created desc 218 + %s`, 219 + whereClause, limitClause) 220 + 221 + rows, err := e.Query(query, args...) 222 + if err != nil { 223 + return nil, err 224 + } 225 + defer rows.Close() 226 + 227 + for rows.Next() { 228 + var issue Issue 229 + var issueCreatedAt string 230 + err := rows.Scan( 231 + &issue.ID, 232 + &issue.OwnerDid, 233 + &issue.RepoAt, 234 + &issue.IssueId, 235 + &issueCreatedAt, 236 + &issue.Title, 237 + &issue.Body, 238 + &issue.Open, 239 + ) 240 + if err != nil { 241 + return nil, err 242 + } 243 + 244 + issueCreatedTime, err := time.Parse(time.RFC3339, issueCreatedAt) 245 + if err != nil { 246 + return nil, err 247 + } 248 + issue.Created = issueCreatedTime 249 + 250 + issues = append(issues, issue) 251 + } 252 + 253 + if err := rows.Err(); err != nil { 254 + return nil, err 255 + } 256 + 257 + return issues, nil 258 + } 259 + 260 + func GetIssues(e Execer, filters ...filter) ([]Issue, error) { 261 + return GetIssuesWithLimit(e, 0, filters...) 183 262 } 184 263 185 264 // timeframe here is directly passed into the sql query filter, and any
+1 -1
appview/issues/issues.go
··· 604 604 return 605 605 } 606 606 607 - issues, err := db.GetIssues(rp.db, f.RepoAt(), isOpen, page) 607 + issues, err := db.GetIssuesPaginated(rp.db, f.RepoAt(), isOpen, page) 608 608 if err != nil { 609 609 log.Println("failed to get issues", err) 610 610 rp.pages.Notice(w, "issues", "Failed to load issues. Try again later.")