diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2021-11-10 04:21:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-09 22:21:01 -0500 |
commit | edbaa5d3f05b5ca397524587ba9db15edd61bc29 (patch) | |
tree | c0359b111705c4873b41c451ccd7076f6ee55c7d /models | |
parent | 465fb4169ecbbef5c460c60f1cdf9b5910610d65 (diff) | |
download | gitea-edbaa5d3f05b5ca397524587ba9db15edd61bc29.tar.gz gitea-edbaa5d3f05b5ca397524587ba9db15edd61bc29.zip |
Added GetUserByIDCtx. (#17602)
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'models')
-rw-r--r-- | models/issue_comment.go | 4 | ||||
-rw-r--r-- | models/issue_reaction.go | 2 | ||||
-rw-r--r-- | models/user.go | 9 |
3 files changed, 10 insertions, 5 deletions
diff --git a/models/issue_comment.go b/models/issue_comment.go index 0ae9140f0c..ad10b53b37 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -488,7 +488,7 @@ func (c *Comment) LoadAssigneeUserAndTeam() error { var err error if c.AssigneeID > 0 && c.Assignee == nil { - c.Assignee, err = getUserByID(db.GetEngine(db.DefaultContext), c.AssigneeID) + c.Assignee, err = GetUserByIDCtx(db.DefaultContext, c.AssigneeID) if err != nil { if !IsErrUserNotExist(err) { return err @@ -523,7 +523,7 @@ func (c *Comment) LoadResolveDoer() (err error) { if c.ResolveDoerID == 0 || c.Type != CommentTypeCode { return nil } - c.ResolveDoer, err = getUserByID(db.GetEngine(db.DefaultContext), c.ResolveDoerID) + c.ResolveDoer, err = GetUserByIDCtx(db.DefaultContext, c.ResolveDoerID) if err != nil { if IsErrUserNotExist(err) { c.ResolveDoer = NewGhostUser() diff --git a/models/issue_reaction.go b/models/issue_reaction.go index 423eb8b96c..2f64609e99 100644 --- a/models/issue_reaction.go +++ b/models/issue_reaction.go @@ -240,7 +240,7 @@ func (r *Reaction) LoadUser() (*User, error) { if r.User != nil { return r.User, nil } - user, err := getUserByID(db.GetEngine(db.DefaultContext), r.UserID) + user, err := GetUserByIDCtx(db.DefaultContext, r.UserID) if err != nil { return nil, err } diff --git a/models/user.go b/models/user.go index bf4444802f..d27c581bab 100644 --- a/models/user.go +++ b/models/user.go @@ -1392,7 +1392,12 @@ func getUserByID(e db.Engine, id int64) (*User, error) { // GetUserByID returns the user object by given ID if exists. func GetUserByID(id int64) (*User, error) { - return getUserByID(db.GetEngine(db.DefaultContext), id) + return GetUserByIDCtx(db.DefaultContext, id) +} + +// GetUserByIDCtx returns the user object by given ID if exists. +func GetUserByIDCtx(ctx context.Context, id int64) (*User, error) { + return getUserByID(db.GetEngine(ctx), id) } // GetUserByName returns user by given name. @@ -1577,7 +1582,7 @@ func GetUserByEmailContext(ctx context.Context, email string) (*User, error) { return nil, err } if has { - return getUserByID(db.GetEngine(ctx), emailAddress.UID) + return GetUserByIDCtx(ctx, emailAddress.UID) } // Finally, if email address is the protected email address: |