From 925930f76f7d2a91b09b1251296ce3d1beeb5ee6 Mon Sep 17 00:00:00 2001 From: Joel Valentine Date: Sat, 31 Aug 2019 17:24:13 +0100 Subject: [PATCH] addressing performance --- modules/github/display.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/modules/github/display.go b/modules/github/display.go index 45e38ac0..53b3fd00 100644 --- a/modules/github/display.go +++ b/modules/github/display.go @@ -36,12 +36,14 @@ func (widget *Widget) content() (string, string, bool) { func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) string { prs := repo.myPullRequests(username, widget.settings.enableStatus) + + prLength := len(prs) - if len(prs) == 0 { + if prLength == 0 { return " [grey]none[white]\n" } - widget.SetItemCount(len(prs)) + widget.SetItemCount(prLength) str := "" for idx, pr := range prs { @@ -55,23 +57,25 @@ func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) s func (widget *Widget) displayCustomQuery(repo *GithubRepo, filter string, perPage int) string { res := repo.customIssueQuery(filter, perPage) - maxItems := widget.GetItemCount() - if res == nil { return " [grey]Invalid Query[white]\n" } - if len(res.Issues) == 0 { + issuesLength := len(res.Issues) + + if issuesLength == 0 { return " [grey]none[white]\n" } + + maxItems := widget.GetItemCount() str := "" for idx, issue := range res.Issues { - str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, maxItems + idx, *issue.Number, *issue.Title) + str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, maxItems + idx , *issue.Number, *issue.Title) str += "\n" } - widget.SetItemCount(maxItems + len(res.Issues)) + widget.SetItemCount(maxItems + issuesLength) return str } @@ -79,19 +83,21 @@ func (widget *Widget) displayCustomQuery(repo *GithubRepo, filter string, perPag func (widget *Widget) displayMyReviewRequests(repo *GithubRepo, username string) string { prs := repo.myReviewRequests(username) - maxItems := widget.GetItemCount() + prLength := len(prs) - if len(prs) == 0 { + if prLength == 0 { return " [grey]none[white]\n" } + maxItems := widget.GetItemCount() + str := "" for idx, pr := range prs { str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, maxItems + idx, *pr.Number, *pr.Title) str += "\n" } - widget.SetItemCount(maxItems + len(prs)) + widget.SetItemCount(maxItems + prLength) return str }