5
5
package models
6
6
7
7
import (
8
+ "context"
8
9
"fmt"
9
10
10
11
"code.gitea.io/gitea/models/db"
@@ -26,14 +27,14 @@ func (actions ActionList) getUserIDs() []int64 {
26
27
return container .KeysInt64 (userIDs )
27
28
}
28
29
29
- func (actions ActionList ) loadUsers (e db. Engine ) (map [int64 ]* user_model.User , error ) {
30
+ func (actions ActionList ) loadUsers (ctx context. Context ) (map [int64 ]* user_model.User , error ) {
30
31
if len (actions ) == 0 {
31
32
return nil , nil
32
33
}
33
34
34
35
userIDs := actions .getUserIDs ()
35
36
userMaps := make (map [int64 ]* user_model.User , len (userIDs ))
36
- err := e .
37
+ err := db . GetEngine ( ctx ) .
37
38
In ("id" , userIDs ).
38
39
Find (& userMaps )
39
40
if err != nil {
@@ -56,14 +57,14 @@ func (actions ActionList) getRepoIDs() []int64 {
56
57
return container .KeysInt64 (repoIDs )
57
58
}
58
59
59
- func (actions ActionList ) loadRepositories (e db. Engine ) error {
60
+ func (actions ActionList ) loadRepositories (ctx context. Context ) error {
60
61
if len (actions ) == 0 {
61
62
return nil
62
63
}
63
64
64
65
repoIDs := actions .getRepoIDs ()
65
66
repoMaps := make (map [int64 ]* repo_model.Repository , len (repoIDs ))
66
- err := e .In ("id" , repoIDs ).Find (& repoMaps )
67
+ err := db . GetEngine ( ctx ) .In ("id" , repoIDs ).Find (& repoMaps )
67
68
if err != nil {
68
69
return fmt .Errorf ("find repository: %v" , err )
69
70
}
@@ -74,7 +75,7 @@ func (actions ActionList) loadRepositories(e db.Engine) error {
74
75
return nil
75
76
}
76
77
77
- func (actions ActionList ) loadRepoOwner (e db. Engine , userMap map [int64 ]* user_model.User ) (err error ) {
78
+ func (actions ActionList ) loadRepoOwner (ctx context. Context , userMap map [int64 ]* user_model.User ) (err error ) {
78
79
if userMap == nil {
79
80
userMap = make (map [int64 ]* user_model.User )
80
81
}
@@ -85,7 +86,7 @@ func (actions ActionList) loadRepoOwner(e db.Engine, userMap map[int64]*user_mod
85
86
}
86
87
repoOwner , ok := userMap [action .Repo .OwnerID ]
87
88
if ! ok {
88
- repoOwner , err = user_model .GetUserByID ( action .Repo .OwnerID )
89
+ repoOwner , err = user_model .GetUserByIDCtx ( ctx , action .Repo .OwnerID )
89
90
if err != nil {
90
91
if user_model .IsErrUserNotExist (err ) {
91
92
continue
@@ -101,15 +102,15 @@ func (actions ActionList) loadRepoOwner(e db.Engine, userMap map[int64]*user_mod
101
102
}
102
103
103
104
// loadAttributes loads all attributes
104
- func (actions ActionList ) loadAttributes (e db. Engine ) error {
105
- userMap , err := actions .loadUsers (e )
105
+ func (actions ActionList ) loadAttributes (ctx context. Context ) error {
106
+ userMap , err := actions .loadUsers (ctx )
106
107
if err != nil {
107
108
return err
108
109
}
109
110
110
- if err := actions .loadRepositories (e ); err != nil {
111
+ if err := actions .loadRepositories (ctx ); err != nil {
111
112
return err
112
113
}
113
114
114
- return actions .loadRepoOwner (e , userMap )
115
+ return actions .loadRepoOwner (ctx , userMap )
115
116
}
0 commit comments