aboutsummaryrefslogtreecommitdiffstats
path: root/models/issues/issue_list.go
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2022-10-12 07:18:26 +0200
committerGitHub <noreply@github.com>2022-10-12 13:18:26 +0800
commit0e57ff7eee4ac71d923f970d15889ad4d50f97a9 (patch)
treee5a92c55af5366924bd40ae14b4bf12842239193 /models/issues/issue_list.go
parente84558b0931309cf1f4f2767bc47296483b9b3e1 (diff)
downloadgitea-0e57ff7eee4ac71d923f970d15889ad4d50f97a9.tar.gz
gitea-0e57ff7eee4ac71d923f970d15889ad4d50f97a9.zip
Add generic set type (#21408)
This PR adds a generic set type to get rid of maps used as sets. Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'models/issues/issue_list.go')
-rw-r--r--models/issues/issue_list.go33
1 files changed, 13 insertions, 20 deletions
diff --git a/models/issues/issue_list.go b/models/issues/issue_list.go
index 874f2a6368..deadb6a564 100644
--- a/models/issues/issue_list.go
+++ b/models/issues/issue_list.go
@@ -22,16 +22,16 @@ type IssueList []*Issue
// get the repo IDs to be loaded later, these IDs are for issue.Repo and issue.PullRequest.HeadRepo
func (issues IssueList) getRepoIDs() []int64 {
- repoIDs := make(map[int64]struct{}, len(issues))
+ repoIDs := make(container.Set[int64], len(issues))
for _, issue := range issues {
if issue.Repo == nil {
- repoIDs[issue.RepoID] = struct{}{}
+ repoIDs.Add(issue.RepoID)
}
if issue.PullRequest != nil && issue.PullRequest.HeadRepo == nil {
- repoIDs[issue.PullRequest.HeadRepoID] = struct{}{}
+ repoIDs.Add(issue.PullRequest.HeadRepoID)
}
}
- return container.KeysInt64(repoIDs)
+ return repoIDs.Values()
}
func (issues IssueList) loadRepositories(ctx context.Context) ([]*repo_model.Repository, error) {
@@ -79,13 +79,11 @@ func (issues IssueList) LoadRepositories() ([]*repo_model.Repository, error) {
}
func (issues IssueList) getPosterIDs() []int64 {
- posterIDs := make(map[int64]struct{}, len(issues))
+ posterIDs := make(container.Set[int64], len(issues))
for _, issue := range issues {
- if _, ok := posterIDs[issue.PosterID]; !ok {
- posterIDs[issue.PosterID] = struct{}{}
- }
+ posterIDs.Add(issue.PosterID)
}
- return container.KeysInt64(posterIDs)
+ return posterIDs.Values()
}
func (issues IssueList) loadPosters(ctx context.Context) error {
@@ -185,13 +183,11 @@ func (issues IssueList) loadLabels(ctx context.Context) error {
}
func (issues IssueList) getMilestoneIDs() []int64 {
- ids := make(map[int64]struct{}, len(issues))
+ ids := make(container.Set[int64], len(issues))
for _, issue := range issues {
- if _, ok := ids[issue.MilestoneID]; !ok {
- ids[issue.MilestoneID] = struct{}{}
- }
+ ids.Add(issue.MilestoneID)
}
- return container.KeysInt64(ids)
+ return ids.Values()
}
func (issues IssueList) loadMilestones(ctx context.Context) error {
@@ -224,14 +220,11 @@ func (issues IssueList) loadMilestones(ctx context.Context) error {
}
func (issues IssueList) getProjectIDs() []int64 {
- ids := make(map[int64]struct{}, len(issues))
+ ids := make(container.Set[int64], len(issues))
for _, issue := range issues {
- projectID := issue.ProjectID()
- if _, ok := ids[projectID]; !ok {
- ids[projectID] = struct{}{}
- }
+ ids.Add(issue.ProjectID())
}
- return container.KeysInt64(ids)
+ return ids.Values()
}
func (issues IssueList) loadProjects(ctx context.Context) error {