From ed19b8bdd7e4876a15cb5346f0b0a3e684c20036 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 12 Apr 2024 05:54:45 +0000 Subject: [PATCH] use container.FilterSlice --- models/git/branch_list.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/models/git/branch_list.go b/models/git/branch_list.go index 03e81a38b8..653886e371 100644 --- a/models/git/branch_list.go +++ b/models/git/branch_list.go @@ -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 {