perf: drop wasted requests and reuse markdown renderers

pr edit with reviewers and other fields reads the pull request once,
org delete counts only repositories, org view counts concurrently,
team list skips the repository count of all-repository teams,
pr diff --web builds the URL locally, pr list re-reads pull requests
concurrently for review fields, and glamour renderers are built once
per width and color.

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-12 18:44:29 +02:00
1 parent af14803b3a
commit 8bf979099b
8 files changed
+104 -47

No files matched your search

+17 -6
View File
@@ -236,6 +236,17 @@ func (s Pulls) View(ctx context.Context, n int64) (Pull, error) {
return pullFrom(pull), nil
}
// ViewAll retrieves each of items again, a few at a time, for the fields only a single pull
// request carries, such as its reviewers.
func (s Pulls) ViewAll(ctx context.Context, items []Pull) ([]Pull, error) {
viewed := make([]Pull, len(items))
err := concurrently(len(items), func(i int) (err error) {
viewed[i], err = s.View(ctx, items[i].Number)
return err
})
return viewed, err
}
func (s Pulls) get(ctx context.Context, n int64) (*gitea.PullRequest, error) {
item, err := repoCall(ctx, s.Client, s.Repository, func(ctx context.Context, c *gitea.Client, owner, name string) (*gitea.PullRequest, *gitea.Response, error) {
return c.PullRequests.GetPullRequest(ctx, owner, name, n)
@@ -264,15 +275,15 @@ func (s Pulls) Create(ctx context.Context, opts PullOptions) (Pull, error) {
// Edit updates only explicitly supplied resource fields.
func (s Pulls) Edit(ctx context.Context, n int64, opts PullEdit) (Pull, error) {
if opts.ReviewerChanges != nil {
item, err := (Reviews{Client: s.Client, Repository: s.Repository}).ChangeRequests(ctx, n, *opts.ReviewerChanges)
if err != nil {
return Pull{}, err
}
reviews, changes := Reviews{Client: s.Client, Repository: s.Repository}, opts.ReviewerChanges
opts.ReviewerChanges = nil
if opts == (PullEdit{}) {
return item, nil
return reviews.ChangeRequests(ctx, n, *changes)
}
item, err = s.Edit(ctx, n, opts)
if err := reviews.changeRequests(ctx, n, *changes); err != nil {
return Pull{}, err
}
item, err := s.Edit(ctx, n, opts)
if err != nil {
return Pull{}, fmt.Errorf("review requests were updated, but editing other pull request fields failed: %w", err)
}