@@ -22,11 +22,9 @@ import (
2222type ActionList []* Action
2323
2424func (actions ActionList ) getUserIDs () []int64 {
25- userIDs := make (container.Set [int64 ], len (actions ))
26- for _ , action := range actions {
27- userIDs .Add (action .ActUserID )
28- }
29- return userIDs .Values ()
25+ return container .FilterSlice (actions , func (action * Action ) (int64 , bool ) {
26+ return action .ActUserID , true
27+ })
3028}
3129
3230func (actions ActionList ) LoadActUsers (ctx context.Context ) (map [int64 ]* user_model.User , error ) {
@@ -50,11 +48,9 @@ func (actions ActionList) LoadActUsers(ctx context.Context) (map[int64]*user_mod
5048}
5149
5250func (actions ActionList ) getRepoIDs () []int64 {
53- repoIDs := make (container.Set [int64 ], len (actions ))
54- for _ , action := range actions {
55- repoIDs .Add (action .RepoID )
56- }
57- return repoIDs .Values ()
51+ return container .FilterSlice (actions , func (action * Action ) (int64 , bool ) {
52+ return action .RepoID , true
53+ })
5854}
5955
6056func (actions ActionList ) LoadRepositories (ctx context.Context ) error {
@@ -80,18 +76,16 @@ func (actions ActionList) loadRepoOwner(ctx context.Context, userMap map[int64]*
8076 userMap = make (map [int64 ]* user_model.User )
8177 }
8278
83- userSet := make (container.Set [int64 ], len (actions ))
84- for _ , action := range actions {
79+ missingUserIDs := container .FilterSlice (actions , func (action * Action ) (int64 , bool ) {
8580 if action .Repo == nil {
86- continue
81+ return 0 , false
8782 }
88- if _ , ok := userMap [action .Repo .OwnerID ]; ! ok {
89- userSet .Add (action .Repo .OwnerID )
90- }
91- }
83+ _ , alreadyLoaded := userMap [action .Repo .OwnerID ]
84+ return action .Repo .OwnerID , ! alreadyLoaded
85+ })
9286
9387 if err := db .GetEngine (ctx ).
94- In ("id" , userSet . Values () ).
88+ In ("id" , missingUserIDs ).
9589 Find (& userMap ); err != nil {
9690 return fmt .Errorf ("find user: %w" , err )
9791 }
0 commit comments