Signed-off-by: dusk y.bera003.06@protonmail.com
+13
-56
appview/db/pulls.go
+13
-56
appview/db/pulls.go
···
310
310
return pullId - 1, err
311
311
}
312
312
313
-
func GetPulls(e Execer, filters ...filter) ([]*Pull, error) {
313
+
func GetPullsWithLimit(e Execer, limit int, filters ...filter) ([]*Pull, error) {
314
314
pulls := make(map[int]*Pull)
315
315
316
316
var conditions []string
···
324
324
if conditions != nil {
325
325
whereClause = " where " + strings.Join(conditions, " and ")
326
326
}
327
+
limitClause := ""
328
+
if limit != 0 {
329
+
limitClause = fmt.Sprintf(" limit %d ", limit)
330
+
}
327
331
328
332
query := fmt.Sprintf(`
329
333
select
···
344
348
from
345
349
pulls
346
350
%s
347
-
`, whereClause)
351
+
order by
352
+
created desc
353
+
%s
354
+
`, whereClause, limitClause)
348
355
349
356
rows, err := e.Query(query, args...)
350
357
if err != nil {
···
513
520
return orderedByPullId, nil
514
521
}
515
522
523
+
func GetPulls(e Execer, filters ...filter) ([]*Pull, error) {
524
+
return GetPullsWithLimit(e, 0, filters...)
525
+
}
526
+
516
527
func GetPull(e Execer, repoAt syntax.ATURI, pullId int) (*Pull, error) {
517
528
query := `
518
529
select
···
723
734
return &pull, nil
724
735
}
725
736
726
-
func GetAnyPulls(e Execer, repoAt syntax.ATURI, count int) ([]Pull, error) {
727
-
pulls := make([]Pull, 0, count)
728
-
729
-
rows, err := e.Query(`
730
-
select
731
-
p.owner_did,
732
-
p.repo_at,
733
-
p.pull_id,
734
-
p.created,
735
-
p.title,
736
-
p.state
737
-
from
738
-
pulls p
739
-
where
740
-
p.repo_at = ?
741
-
order by
742
-
p.created desc`,
743
-
repoAt)
744
-
if err != nil {
745
-
return nil, err
746
-
}
747
-
defer rows.Close()
748
-
749
-
for rows.Next() {
750
-
var pull Pull
751
-
var pullCreatedAt string
752
-
err := rows.Scan(
753
-
&pull.OwnerDid,
754
-
&pull.RepoAt,
755
-
&pull.PullId,
756
-
&pullCreatedAt,
757
-
&pull.Title,
758
-
&pull.State,
759
-
)
760
-
if err != nil {
761
-
return nil, err
762
-
}
763
-
764
-
pullCreatedTime, err := time.Parse(time.RFC3339, pullCreatedAt)
765
-
if err != nil {
766
-
return nil, err
767
-
}
768
-
pull.Created = pullCreatedTime
769
-
770
-
pulls = append(pulls, pull)
771
-
}
772
-
773
-
if err := rows.Err(); err != nil {
774
-
return nil, err
775
-
}
776
-
777
-
return pulls, nil
778
-
}
779
-
780
737
// timeframe here is directly passed into the sql query filter, and any
781
738
// timeframe in the past should be negative; e.g.: "-3 months"
782
739
func GetPullsByOwnerDid(e Execer, did, timeframe string) ([]Pull, error) {
History
3 rounds
5 comments
expand 1 comment
pull request successfully merged
expand 0 comments
expand 4 comments
why not use GetPulls with filters instead? we can additionally utilize things like comments and rounds in the feed.
right; i was going for no comments / rounds at first but that makes more sense!
(i think comments would be too noisy, thats best left to notifications IMO, but rounds would be fine)
removed that and modified GetPulls a bit and using that
submission created times were not being read from db, fixed