diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2023-05-19 22:17:48 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-19 22:17:48 +0800 |
commit | 38cf43d0606c13c38f459659f38e26cf31dceccb (patch) | |
tree | 53cae445e91b7448ae37a00a7ae398aa082f958d /routers | |
parent | c757765a9e5c2d4f73b1a7c3debe3548c735bd54 (diff) | |
download | gitea-38cf43d0606c13c38f459659f38e26cf31dceccb.tar.gz gitea-38cf43d0606c13c38f459659f38e26cf31dceccb.zip |
Some refactors for issues stats (#24793)
This PR
- [x] Move some functions from `issues.go` to `issue_stats.go` and
`issue_label.go`
- [x] Remove duplicated issue options `UserIssueStatsOption` to keep
only one `IssuesOptions`
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/repo/issue.go | 2 | ||||
-rw-r--r-- | routers/web/repo/issue.go | 6 | ||||
-rw-r--r-- | routers/web/user/home.go | 28 |
3 files changed, 16 insertions, 20 deletions
diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 5bf5fc8c8b..95528d664d 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -470,7 +470,7 @@ func ListIssues(ctx *context.APIContext) { if len(keyword) == 0 || len(issueIDs) > 0 || len(labelIDs) > 0 { issuesOpt := &issues_model.IssuesOptions{ ListOptions: listOptions, - RepoID: ctx.Repo.Repository.ID, + RepoIDs: []int64{ctx.Repo.Repository.ID}, IsClosed: isClosed, IssueIDs: issueIDs, LabelIDs: labelIDs, diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index cb0aaa3db5..88d2a97a7a 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -207,7 +207,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti issueStats = &issues_model.IssueStats{} } else { issueStats, err = issues_model.GetIssueStats(&issues_model.IssuesOptions{ - RepoID: repo.ID, + RepoIDs: []int64{repo.ID}, LabelIDs: labelIDs, MilestoneIDs: []int64{milestoneID}, ProjectID: projectID, @@ -258,7 +258,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti Page: pager.Paginater.Current(), PageSize: setting.UI.IssuePagingNum, }, - RepoID: repo.ID, + RepoIDs: []int64{repo.ID}, AssigneeID: assigneeID, PosterID: posterID, MentionedID: mentionedID, @@ -2652,7 +2652,7 @@ func ListIssues(ctx *context.Context) { if len(keyword) == 0 || len(issueIDs) > 0 || len(labelIDs) > 0 { issuesOpt := &issues_model.IssuesOptions{ ListOptions: listOptions, - RepoID: ctx.Repo.Repository.ID, + RepoIDs: []int64{ctx.Repo.Repository.ID}, IsClosed: isClosed, IssueIDs: issueIDs, LabelIDs: labelIDs, diff --git a/routers/web/user/home.go b/routers/web/user/home.go index 1af56e24b0..2513fc9a98 100644 --- a/routers/web/user/home.go +++ b/routers/web/user/home.go @@ -521,10 +521,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) { // Parse ctx.FormString("repos") and remember matched repo IDs for later. // Gets set when clicking filters on the issues overview page. - repoIDs := getRepoIDs(ctx.FormString("repos")) - if len(repoIDs) > 0 { - opts.RepoCond = builder.In("issue.repo_id", repoIDs) - } + opts.RepoIDs = getRepoIDs(ctx.FormString("repos")) // ------------------------------ // Get issues as defined by opts. @@ -580,11 +577,10 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) { // ------------------------------- var issueStats *issues_model.IssueStats if !forceEmpty { - statsOpts := issues_model.UserIssueStatsOptions{ - UserID: ctx.Doer.ID, - FilterMode: filterMode, - IsPull: isPullList, - IsClosed: isShowClosed, + statsOpts := issues_model.IssuesOptions{ + User: ctx.Doer, + IsPull: util.OptionalBoolOf(isPullList), + IsClosed: util.OptionalBoolOf(isShowClosed), IssueIDs: issueIDsFromSearch, IsArchived: util.OptionalBoolFalse, LabelIDs: opts.LabelIDs, @@ -593,7 +589,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) { RepoCond: opts.RepoCond, } - issueStats, err = issues_model.GetUserIssueStats(statsOpts) + issueStats, err = issues_model.GetUserIssueStats(filterMode, statsOpts) if err != nil { ctx.ServerError("GetUserIssueStats Shown", err) return @@ -609,9 +605,9 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) { } else { shownIssues = int(issueStats.ClosedCount) } - if len(repoIDs) != 0 { + if len(opts.RepoIDs) != 0 { shownIssues = 0 - for _, repoID := range repoIDs { + for _, repoID := range opts.RepoIDs { shownIssues += int(issueCountByRepo[repoID]) } } @@ -622,8 +618,8 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) { } ctx.Data["TotalIssueCount"] = allIssueCount - if len(repoIDs) == 1 { - repo := showReposMap[repoIDs[0]] + if len(opts.RepoIDs) == 1 { + repo := showReposMap[opts.RepoIDs[0]] if repo != nil { ctx.Data["SingleRepoLink"] = repo.Link() } @@ -665,7 +661,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) { ctx.Data["IssueStats"] = issueStats ctx.Data["ViewType"] = viewType ctx.Data["SortType"] = sortType - ctx.Data["RepoIDs"] = repoIDs + ctx.Data["RepoIDs"] = opts.RepoIDs ctx.Data["IsShowClosed"] = isShowClosed ctx.Data["SelectLabels"] = selectedLabels @@ -676,7 +672,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) { } // Convert []int64 to string - reposParam, _ := json.Marshal(repoIDs) + reposParam, _ := json.Marshal(opts.RepoIDs) ctx.Data["ReposParam"] = string(reposParam) |