diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2024-04-10 12:18:41 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-10 04:18:41 +0000 |
commit | b09687f1d18e1489d82dd481a1cce50203f2da94 (patch) | |
tree | c8cccca7096edd3024bf80cbb392491e4a9baf3a | |
parent | 310e2517e5d55a037f612a8561fb1850b517b37f (diff) | |
download | gitea-b09687f1d18e1489d82dd481a1cce50203f2da94.tar.gz gitea-b09687f1d18e1489d82dd481a1cce50203f2da94.zip |
Refactor more filterslice (#30370)
-rw-r--r-- | models/actions/runner_list.go | 13 | ||||
-rw-r--r-- | models/activities/notification_list.go | 12 | ||||
-rw-r--r-- | models/issues/issue_list.go | 11 |
3 files changed, 13 insertions, 23 deletions
diff --git a/models/actions/runner_list.go b/models/actions/runner_list.go index 5ce69e07ac..3ef8ebb254 100644 --- a/models/actions/runner_list.go +++ b/models/actions/runner_list.go @@ -36,16 +36,9 @@ func (runners RunnerList) LoadOwners(ctx context.Context) error { } func (runners RunnerList) getRepoIDs() []int64 { - repoIDs := make(container.Set[int64], len(runners)) - for _, runner := range runners { - if runner.RepoID == 0 { - continue - } - if _, ok := repoIDs[runner.RepoID]; !ok { - repoIDs[runner.RepoID] = struct{}{} - } - } - return repoIDs.Values() + return container.FilterSlice(runners, func(runner *ActionRunner) (int64, bool) { + return runner.RepoID, runner.RepoID > 0 + }) } func (runners RunnerList) LoadRepos(ctx context.Context) error { diff --git a/models/activities/notification_list.go b/models/activities/notification_list.go index 5858933391..0cbb91df3c 100644 --- a/models/activities/notification_list.go +++ b/models/activities/notification_list.go @@ -190,14 +190,12 @@ func (nl NotificationList) LoadAttributes(ctx context.Context) error { } func (nl NotificationList) getPendingRepoIDs() []int64 { - ids := make(container.Set[int64], len(nl)) - for _, notification := range nl { - if notification.Repository != nil { - continue + return container.FilterSlice(nl, func(n *Notification) (int64, bool) { + if n.Repository != nil { + return 0, false } - ids.Add(notification.RepoID) - } - return ids.Values() + return n.RepoID, true + }) } // LoadRepos loads repositories from database diff --git a/models/issues/issue_list.go b/models/issues/issue_list.go index 1b05f0aa35..f8ee271a6b 100644 --- a/models/issues/issue_list.go +++ b/models/issues/issue_list.go @@ -21,16 +21,15 @@ 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(container.Set[int64], len(issues)) - for _, issue := range issues { + return container.FilterSlice(issues, func(issue *Issue) (int64, bool) { if issue.Repo == nil { - repoIDs.Add(issue.RepoID) + return issue.RepoID, true } if issue.PullRequest != nil && issue.PullRequest.HeadRepo == nil { - repoIDs.Add(issue.PullRequest.HeadRepoID) + return issue.PullRequest.HeadRepoID, true } - } - return repoIDs.Values() + return 0, false + }) } // LoadRepositories loads issues' all repositories |