mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-24 22:36:17 +02:00
fix: use container.Set
This commit is contained in:
parent
5925722501
commit
5d938ebf4e
@ -7,6 +7,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
"code.gitea.io/gitea/modules/container"
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
|
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
@ -15,18 +16,14 @@ import (
|
|||||||
type ActionJobList []*ActionRunJob
|
type ActionJobList []*ActionRunJob
|
||||||
|
|
||||||
func (jobs ActionJobList) GetRunIDs() []int64 {
|
func (jobs ActionJobList) GetRunIDs() []int64 {
|
||||||
runIDsMap := make(map[int64]struct{})
|
ids := make(container.Set[int64], len(jobs))
|
||||||
for _, j := range jobs {
|
for _, j := range jobs {
|
||||||
if j.RunID == 0 {
|
if j.RunID == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
runIDsMap[j.RunID] = struct{}{}
|
ids.Add(j.RunID)
|
||||||
}
|
}
|
||||||
runIDs := make([]int64, 0, len(runIDsMap))
|
return ids.Values()
|
||||||
for runID := range runIDsMap {
|
|
||||||
runIDs = append(runIDs, runID)
|
|
||||||
}
|
|
||||||
return runIDs
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (jobs ActionJobList) LoadRuns(ctx context.Context, withRepo bool) error {
|
func (jobs ActionJobList) LoadRuns(ctx context.Context, withRepo bool) error {
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
"code.gitea.io/gitea/modules/container"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
|
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
@ -18,27 +19,19 @@ type RunList []*ActionRun
|
|||||||
|
|
||||||
// GetUserIDs returns a slice of user's id
|
// GetUserIDs returns a slice of user's id
|
||||||
func (runs RunList) GetUserIDs() []int64 {
|
func (runs RunList) GetUserIDs() []int64 {
|
||||||
userIDsMap := make(map[int64]struct{})
|
ids := make(container.Set[int64], len(runs))
|
||||||
for _, run := range runs {
|
for _, run := range runs {
|
||||||
userIDsMap[run.TriggerUserID] = struct{}{}
|
ids.Add(run.TriggerUserID)
|
||||||
}
|
}
|
||||||
userIDs := make([]int64, 0, len(userIDsMap))
|
return ids.Values()
|
||||||
for userID := range userIDsMap {
|
|
||||||
userIDs = append(userIDs, userID)
|
|
||||||
}
|
|
||||||
return userIDs
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (runs RunList) GetRepoIDs() []int64 {
|
func (runs RunList) GetRepoIDs() []int64 {
|
||||||
repoIDsMap := make(map[int64]struct{})
|
ids := make(container.Set[int64], len(runs))
|
||||||
for _, run := range runs {
|
for _, run := range runs {
|
||||||
repoIDsMap[run.RepoID] = struct{}{}
|
ids.Add(run.RepoID)
|
||||||
}
|
}
|
||||||
repoIDs := make([]int64, 0, len(repoIDsMap))
|
return ids.Values()
|
||||||
for repoID := range repoIDsMap {
|
|
||||||
repoIDs = append(repoIDs, repoID)
|
|
||||||
}
|
|
||||||
return repoIDs
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (runs RunList) LoadTriggerUser(ctx context.Context) error {
|
func (runs RunList) LoadTriggerUser(ctx context.Context) error {
|
||||||
|
@ -16,18 +16,14 @@ type RunnerList []*ActionRunner
|
|||||||
|
|
||||||
// GetUserIDs returns a slice of user's id
|
// GetUserIDs returns a slice of user's id
|
||||||
func (runners RunnerList) GetUserIDs() []int64 {
|
func (runners RunnerList) GetUserIDs() []int64 {
|
||||||
userIDsMap := make(map[int64]struct{})
|
ids := make(container.Set[int64], len(runners))
|
||||||
for _, runner := range runners {
|
for _, runner := range runners {
|
||||||
if runner.OwnerID == 0 {
|
if runner.OwnerID == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
userIDsMap[runner.OwnerID] = struct{}{}
|
ids.Add(runner.OwnerID)
|
||||||
}
|
}
|
||||||
userIDs := make([]int64, 0, len(userIDsMap))
|
return ids.Values()
|
||||||
for userID := range userIDsMap {
|
|
||||||
userIDs = append(userIDs, userID)
|
|
||||||
}
|
|
||||||
return userIDs
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (runners RunnerList) LoadOwners(ctx context.Context) error {
|
func (runners RunnerList) LoadOwners(ctx context.Context) error {
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
auth_model "code.gitea.io/gitea/models/auth"
|
auth_model "code.gitea.io/gitea/models/auth"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
"code.gitea.io/gitea/modules/container"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
@ -496,12 +497,13 @@ func StopTask(ctx context.Context, taskID int64, status Status) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isSubset(set, subset []string) bool {
|
func isSubset(set, subset []string) bool {
|
||||||
m := make(map[string]struct{}, len(set))
|
m := make(container.Set[string], len(set))
|
||||||
for _, v := range set {
|
for _, v := range set {
|
||||||
m[v] = struct{}{}
|
m.Add(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range subset {
|
for _, v := range subset {
|
||||||
if _, ok := m[v]; !ok {
|
if m.Contains(v) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
"code.gitea.io/gitea/modules/container"
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
|
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
@ -15,18 +16,14 @@ import (
|
|||||||
type TaskList []*ActionTask
|
type TaskList []*ActionTask
|
||||||
|
|
||||||
func (tasks TaskList) GetJobIDs() []int64 {
|
func (tasks TaskList) GetJobIDs() []int64 {
|
||||||
jobIDsMap := make(map[int64]struct{})
|
ids := make(container.Set[int64], len(tasks))
|
||||||
for _, t := range tasks {
|
for _, t := range tasks {
|
||||||
if t.JobID == 0 {
|
if t.JobID == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
jobIDsMap[t.JobID] = struct{}{}
|
ids.Add(t.JobID)
|
||||||
}
|
}
|
||||||
jobIDs := make([]int64, 0, len(jobIDsMap))
|
return ids.Values()
|
||||||
for jobID := range jobIDsMap {
|
|
||||||
jobIDs = append(jobIDs, jobID)
|
|
||||||
}
|
|
||||||
return jobIDs
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tasks TaskList) LoadJobs(ctx context.Context) error {
|
func (tasks TaskList) LoadJobs(ctx context.Context) error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user