@@ -22,11 +22,9 @@ import (
22
22
type ActionList []* Action
23
23
24
24
func (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
+ })
30
28
}
31
29
32
30
func (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
50
48
}
51
49
52
50
func (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
+ })
58
54
}
59
55
60
56
func (actions ActionList ) LoadRepositories (ctx context.Context ) error {
@@ -80,18 +76,16 @@ func (actions ActionList) loadRepoOwner(ctx context.Context, userMap map[int64]*
80
76
userMap = make (map [int64 ]* user_model.User )
81
77
}
82
78
83
- userSet := make (container.Set [int64 ], len (actions ))
84
- for _ , action := range actions {
79
+ missingUserIDs := container .FilterSlice (actions , func (action * Action ) (int64 , bool ) {
85
80
if action .Repo == nil {
86
- continue
81
+ return 0 , false
87
82
}
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
+ })
92
86
93
87
if err := db .GetEngine (ctx ).
94
- In ("id" , userSet . Values () ).
88
+ In ("id" , missingUserIDs ).
95
89
Find (& userMap ); err != nil {
96
90
return fmt .Errorf ("find user: %w" , err )
97
91
}
0 commit comments