55package models
66
77import (
8+ "context"
89 "fmt"
910
1011 "code.gitea.io/gitea/models/db"
@@ -26,14 +27,14 @@ func (actions ActionList) getUserIDs() []int64 {
2627 return container .KeysInt64 (userIDs )
2728}
2829
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 ) {
3031 if len (actions ) == 0 {
3132 return nil , nil
3233 }
3334
3435 userIDs := actions .getUserIDs ()
3536 userMaps := make (map [int64 ]* user_model.User , len (userIDs ))
36- err := e .
37+ err := db . GetEngine ( ctx ) .
3738 In ("id" , userIDs ).
3839 Find (& userMaps )
3940 if err != nil {
@@ -56,14 +57,14 @@ func (actions ActionList) getRepoIDs() []int64 {
5657 return container .KeysInt64 (repoIDs )
5758}
5859
59- func (actions ActionList ) loadRepositories (e db. Engine ) error {
60+ func (actions ActionList ) loadRepositories (ctx context. Context ) error {
6061 if len (actions ) == 0 {
6162 return nil
6263 }
6364
6465 repoIDs := actions .getRepoIDs ()
6566 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 )
6768 if err != nil {
6869 return fmt .Errorf ("find repository: %v" , err )
6970 }
@@ -74,7 +75,7 @@ func (actions ActionList) loadRepositories(e db.Engine) error {
7475 return nil
7576}
7677
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 ) {
7879 if userMap == nil {
7980 userMap = make (map [int64 ]* user_model.User )
8081 }
@@ -85,7 +86,7 @@ func (actions ActionList) loadRepoOwner(e db.Engine, userMap map[int64]*user_mod
8586 }
8687 repoOwner , ok := userMap [action .Repo .OwnerID ]
8788 if ! ok {
88- repoOwner , err = user_model .GetUserByID ( action .Repo .OwnerID )
89+ repoOwner , err = user_model .GetUserByIDCtx ( ctx , action .Repo .OwnerID )
8990 if err != nil {
9091 if user_model .IsErrUserNotExist (err ) {
9192 continue
@@ -101,15 +102,15 @@ func (actions ActionList) loadRepoOwner(e db.Engine, userMap map[int64]*user_mod
101102}
102103
103104// 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 )
106107 if err != nil {
107108 return err
108109 }
109110
110- if err := actions .loadRepositories (e ); err != nil {
111+ if err := actions .loadRepositories (ctx ); err != nil {
111112 return err
112113 }
113114
114- return actions .loadRepoOwner (e , userMap )
115+ return actions .loadRepoOwner (ctx , userMap )
115116}
0 commit comments