Refactor more filterslice (gitea#30370)
This commit is contained in:
parent
525accfae6
commit
44abf6ab47
|
@ -36,16 +36,9 @@ func (runners RunnerList) LoadOwners(ctx context.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (runners RunnerList) getRepoIDs() []int64 {
|
func (runners RunnerList) getRepoIDs() []int64 {
|
||||||
repoIDs := make(container.Set[int64], len(runners))
|
return container.FilterSlice(runners, func(runner *ActionRunner) (int64, bool) {
|
||||||
for _, runner := range runners {
|
return runner.RepoID, runner.RepoID > 0
|
||||||
if runner.RepoID == 0 {
|
})
|
||||||
continue
|
|
||||||
}
|
|
||||||
if _, ok := repoIDs[runner.RepoID]; !ok {
|
|
||||||
repoIDs[runner.RepoID] = struct{}{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return repoIDs.Values()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (runners RunnerList) LoadRepos(ctx context.Context) error {
|
func (runners RunnerList) LoadRepos(ctx context.Context) error {
|
||||||
|
|
|
@ -197,14 +197,12 @@ func (nl NotificationList) LoadAttributes(ctx context.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nl NotificationList) getPendingRepoIDs() []int64 {
|
func (nl NotificationList) getPendingRepoIDs() []int64 {
|
||||||
ids := make(container.Set[int64], len(nl))
|
return container.FilterSlice(nl, func(n *Notification) (int64, bool) {
|
||||||
for _, notification := range nl {
|
if n.Repository != nil {
|
||||||
if notification.Repository != nil {
|
return 0, false
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
ids.Add(notification.RepoID)
|
return n.RepoID, true
|
||||||
}
|
})
|
||||||
return ids.Values()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadRepos loads repositories from database
|
// LoadRepos loads repositories from database
|
||||||
|
|
|
@ -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
|
// get the repo IDs to be loaded later, these IDs are for issue.Repo and issue.PullRequest.HeadRepo
|
||||||
func (issues IssueList) getRepoIDs() []int64 {
|
func (issues IssueList) getRepoIDs() []int64 {
|
||||||
repoIDs := make(container.Set[int64], len(issues))
|
return container.FilterSlice(issues, func(issue *Issue) (int64, bool) {
|
||||||
for _, issue := range issues {
|
|
||||||
if issue.Repo == nil {
|
if issue.Repo == nil {
|
||||||
repoIDs.Add(issue.RepoID)
|
return issue.RepoID, true
|
||||||
}
|
}
|
||||||
if issue.PullRequest != nil && issue.PullRequest.HeadRepo == nil {
|
if issue.PullRequest != nil && issue.PullRequest.HeadRepo == nil {
|
||||||
repoIDs.Add(issue.PullRequest.HeadRepoID)
|
return issue.PullRequest.HeadRepoID, true
|
||||||
}
|
}
|
||||||
}
|
return 0, false
|
||||||
return repoIDs.Values()
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadRepositories loads issues' all repositories
|
// LoadRepositories loads issues' all repositories
|
||||||
|
|
Loading…
Reference in New Issue