use container.FilterSlice

This commit is contained in:
yp05327 2024-04-12 05:54:45 +00:00
parent 58147c14f7
commit ed19b8bdd7
1 changed files with 5 additions and 7 deletions

View File

@ -61,14 +61,12 @@ func (branches BranchList) LoadPusher(ctx context.Context) error {
}
func (branches BranchList) LoadRepo(ctx context.Context) error {
ids := container.Set[int64]{}
for _, branch := range branches {
if branch.RepoID > 0 {
ids.Add(branch.RepoID)
}
}
ids := container.FilterSlice(branches, func(branch *Branch) (int64, bool) {
return branch.RepoID, branch.RepoID > 0
})
reposMap := make(map[int64]*repo_model.Repository, len(ids))
if err := db.GetEngine(ctx).In("id", ids.Values()).Find(&reposMap); err != nil {
if err := db.GetEngine(ctx).In("id", ids).Find(&reposMap); err != nil {
return err
}
for _, branch := range branches {