Skip to content

Commit b09687f

Browse files
authored
Refactor more filterslice (#30370)
1 parent 310e251 commit b09687f

File tree

3 files changed

+13
-23
lines changed

3 files changed

+13
-23
lines changed

models/actions/runner_list.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,9 @@ func (runners RunnerList) LoadOwners(ctx context.Context) error {
3636
}
3737

3838
func (runners RunnerList) getRepoIDs() []int64 {
39-
repoIDs := make(container.Set[int64], len(runners))
40-
for _, runner := range runners {
41-
if runner.RepoID == 0 {
42-
continue
43-
}
44-
if _, ok := repoIDs[runner.RepoID]; !ok {
45-
repoIDs[runner.RepoID] = struct{}{}
46-
}
47-
}
48-
return repoIDs.Values()
39+
return container.FilterSlice(runners, func(runner *ActionRunner) (int64, bool) {
40+
return runner.RepoID, runner.RepoID > 0
41+
})
4942
}
5043

5144
func (runners RunnerList) LoadRepos(ctx context.Context) error {

models/activities/notification_list.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,12 @@ func (nl NotificationList) LoadAttributes(ctx context.Context) error {
190190
}
191191

192192
func (nl NotificationList) getPendingRepoIDs() []int64 {
193-
ids := make(container.Set[int64], len(nl))
194-
for _, notification := range nl {
195-
if notification.Repository != nil {
196-
continue
193+
return container.FilterSlice(nl, func(n *Notification) (int64, bool) {
194+
if n.Repository != nil {
195+
return 0, false
197196
}
198-
ids.Add(notification.RepoID)
199-
}
200-
return ids.Values()
197+
return n.RepoID, true
198+
})
201199
}
202200

203201
// LoadRepos loads repositories from database

models/issues/issue_list.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,15 @@ type IssueList []*Issue
2121

2222
// get the repo IDs to be loaded later, these IDs are for issue.Repo and issue.PullRequest.HeadRepo
2323
func (issues IssueList) getRepoIDs() []int64 {
24-
repoIDs := make(container.Set[int64], len(issues))
25-
for _, issue := range issues {
24+
return container.FilterSlice(issues, func(issue *Issue) (int64, bool) {
2625
if issue.Repo == nil {
27-
repoIDs.Add(issue.RepoID)
26+
return issue.RepoID, true
2827
}
2928
if issue.PullRequest != nil && issue.PullRequest.HeadRepo == nil {
30-
repoIDs.Add(issue.PullRequest.HeadRepoID)
29+
return issue.PullRequest.HeadRepoID, true
3130
}
32-
}
33-
return repoIDs.Values()
31+
return 0, false
32+
})
3433
}
3534

3635
// LoadRepositories loads issues' all repositories

0 commit comments

Comments
 (0)