]> source.dussan.org Git - gitea.git/commitdiff
Refactor more filterslice (#30370)
authorLunny Xiao <xiaolunwen@gmail.com>
Wed, 10 Apr 2024 04:18:41 +0000 (12:18 +0800)
committerGitHub <noreply@github.com>
Wed, 10 Apr 2024 04:18:41 +0000 (04:18 +0000)
models/actions/runner_list.go
models/activities/notification_list.go
models/issues/issue_list.go

index 5ce69e07acfa6dbb8151fb624e5356138980d29c..3ef8ebb25450fc415ad67e0e6636458e8f51d69b 100644 (file)
@@ -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 {
index 5858933391f6ea43bc25828b7fc43e897bbf1583..0cbb91df3cb91766909240628e93d61b0d22582e 100644 (file)
@@ -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
index 1b05f0aa35a52689c1d53af93a37ae8bd61fc3b0..f8ee271a6bbf599669ea3918d2cb86cc548e949f 100644 (file)
@@ -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